idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
10,000 | SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = listEntry(call, aid, aentry, &cid);
osi_auditU(call, PTS_LstEntEvent, code, AUD_ID, aid, AUD_END);
ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid));
return code;
}
| Bypass | 0 | SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = listEntry(call, aid, aentry, &cid);
osi_auditU(call, PTS_LstEntEvent, code, AUD_ID, aid, AUD_END);
ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,001 | SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
{
afs_int32 code;
code = listMax(call, uid, gid);
osi_auditU(call, PTS_LstMaxEvent, code, AUD_END);
ViceLog(125, ("PTS_ListMax: code %d\n", code));
return code;
}
| Bypass | 0 | SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
{
afs_int32 code;
code = listMax(call, uid, gid);
osi_auditU(call, PTS_LstMaxEvent, code, AUD_END);
ViceLog(125, ("PTS_ListMax: code %d\n", code));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,002 | SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *lastP)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = listOwned(call, aid, alist, lastP, &cid);
osi_auditU(call, PTS_LstOwnEvent, code, AUD_ID, aid, AUD_END);
ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid));
return code;
}
| Bypass | 0 | SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *lastP)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = listOwned(call, aid, alist, lastP, &cid);
osi_auditU(call, PTS_LstOwnEvent, code, AUD_ID, aid, AUD_END);
ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,003 | SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *over)
{
#if defined(SUPERGROUPS)
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = listSuperGroups(call, aid, alist, over, &cid);
osi_auditU(call, PTS_LstSGrps, code, AUD_ID, aid, AUD_END);
ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid));
return code;
#else
return RXGEN_OPCODE;
#endif
}
| Bypass | 0 | SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *over)
{
#if defined(SUPERGROUPS)
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = listSuperGroups(call, aid, alist, over, &cid);
osi_auditU(call, PTS_LstSGrps, code, AUD_ID, aid, AUD_END);
ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid));
return code;
#else
return RXGEN_OPCODE;
#endif
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,004 | SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
{
afs_int32 code;
code = nameToID(call, aname, aid);
osi_auditU(call, PTS_NmToIdEvent, code, AUD_END);
ViceLog(125, ("PTS_NameToID: code %d\n", code));
return code;
}
| Bypass | 0 | SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
{
afs_int32 code;
code = nameToID(call, aname, aid);
osi_auditU(call, PTS_NmToIdEvent, code, AUD_END);
ViceLog(125, ("PTS_NameToID: code %d\n", code));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,005 | SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = removeFromGroup(call, aid, gid, &cid);
osi_auditU(call, PTS_RmFmGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
AUD_END);
ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
return code;
}
| Bypass | 0 | SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = removeFromGroup(call, aid, gid, &cid);
osi_auditU(call, PTS_RmFmGrpEvent, code, AUD_ID, gid, AUD_ID, aid,
AUD_END);
ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,006 | SPR_SetFieldsEntry(struct rx_call *call,
afs_int32 id,
afs_int32 mask, /* specify which fields to update */
afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
afs_int32 spare1, afs_int32 spare2)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code =
setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
spare2, &cid);
osi_auditU(call, PTS_SetFldEntEvent, code, AUD_ID, id, AUD_END);
ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id));
return code;
}
| Bypass | 0 | SPR_SetFieldsEntry(struct rx_call *call,
afs_int32 id,
afs_int32 mask, /* specify which fields to update */
afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
afs_int32 spare1, afs_int32 spare2)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code =
setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
spare2, &cid);
osi_auditU(call, PTS_SetFldEntEvent, code, AUD_ID, id, AUD_END);
ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,007 | SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = setMax(call, aid, gflag, &cid);
osi_auditU(call, PTS_SetMaxEvent, code, AUD_ID, aid, AUD_LONG, gflag,
AUD_END);
ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag));
return code;
}
| Bypass | 0 | SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = setMax(call, aid, gflag, &cid);
osi_auditU(call, PTS_SetMaxEvent, code, AUD_ID, aid, AUD_LONG, gflag,
AUD_END);
ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,008 | SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
struct PrUpdateEntry *uentry)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = UpdateEntry(call, aid, name, uentry, &cid);
osi_auditU(call, PTS_UpdEntEvent, code, AUD_ID, aid, AUD_STR, name, AUD_END);
ViceLog(5, ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n", code, cid, aid, name));
return code;
}
| Bypass | 0 | SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
struct PrUpdateEntry *uentry)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = UpdateEntry(call, aid, name, uentry, &cid);
osi_auditU(call, PTS_UpdEntEvent, code, AUD_ID, aid, AUD_STR, name, AUD_END);
ViceLog(5, ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n", code, cid, aid, name));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,009 | SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = whereIsIt(call, aid, apos, &cid);
osi_auditU(call, PTS_WheIsItEvent, code, AUD_ID, aid, AUD_LONG, *apos,
AUD_END);
ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos));
return code;
}
| Bypass | 0 | SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos)
{
afs_int32 code;
afs_int32 cid = ANONYMOUSID;
code = whereIsIt(call, aid, apos, &cid);
osi_auditU(call, PTS_WheIsItEvent, code, AUD_ID, aid, AUD_LONG, *apos,
AUD_END);
ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos));
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,010 | UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
struct PrUpdateEntry *uentry, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
struct prentry tentry;
afs_int32 loc;
int id = 0;
code = Initdb();
if (code)
return code;
if (code != PRSUCCESS)
return code;
if (aid) {
id = aid;
if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
|| aid == ANONYMOUSID)
return PRPERM;
}
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
code = IsAMemberOf(tt, *cid, SYSADMINID);
if (!code && !pr_noAuth)
ABORT_WITH(tt, PRPERM);
/* Read in entry to be deleted */
if (id) {
loc = FindByID(tt, aid);
} else {
loc = FindByName(tt, name, &tentry);
}
if (loc == 0)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, loc, &tentry);
if (code)
ABORT_WITH(tt, PRDBFAIL);
if (uentry->Mask & PRUPDATE_NAMEHASH) {
int tloc;
code = RemoveFromNameHash(tt, tentry.name, &tloc);
if (code != PRSUCCESS)
ABORT_WITH(tt, PRDBFAIL);
code = AddToNameHash(tt, tentry.name, loc);
if (code)
ABORT_WITH(tt, code);
}
if (uentry->Mask & PRUPDATE_IDHASH) {
int tloc;
if (!id)
id = tentry.id;
code = RemoveFromIDHash(tt, id, &tloc);
if (code != PRSUCCESS)
ABORT_WITH(tt, PRDBFAIL);
code = AddToIDHash(tt, id, loc);
if (code)
ABORT_WITH(tt, code);
}
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
struct PrUpdateEntry *uentry, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
struct prentry tentry;
afs_int32 loc;
int id = 0;
code = Initdb();
if (code)
return code;
if (code != PRSUCCESS)
return code;
if (aid) {
id = aid;
if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
|| aid == ANONYMOUSID)
return PRPERM;
}
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
code = IsAMemberOf(tt, *cid, SYSADMINID);
if (!code && !pr_noAuth)
ABORT_WITH(tt, PRPERM);
/* Read in entry to be deleted */
if (id) {
loc = FindByID(tt, aid);
} else {
loc = FindByName(tt, name, &tentry);
}
if (loc == 0)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, loc, &tentry);
if (code)
ABORT_WITH(tt, PRDBFAIL);
if (uentry->Mask & PRUPDATE_NAMEHASH) {
int tloc;
code = RemoveFromNameHash(tt, tentry.name, &tloc);
if (code != PRSUCCESS)
ABORT_WITH(tt, PRDBFAIL);
code = AddToNameHash(tt, tentry.name, loc);
if (code)
ABORT_WITH(tt, code);
}
if (uentry->Mask & PRUPDATE_IDHASH) {
int tloc;
if (!id)
id = tentry.id;
code = RemoveFromIDHash(tt, id, &tloc);
if (code != PRSUCCESS)
ABORT_WITH(tt, PRDBFAIL);
code = AddToIDHash(tt, id, loc);
if (code)
ABORT_WITH(tt, code);
}
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,011 | WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid)
{
int foreign = 0;
/* aid is set to the identity of the caller, if known, else ANONYMOUSID */
/* returns -1 and sets aid to ANONYMOUSID on any failure */
struct rx_connection *tconn;
afs_int32 code;
char tcell[MAXKTCREALMLEN];
char name[MAXKTCNAMELEN];
char inst[MAXKTCNAMELEN];
int ilen;
char vname[256];
*aid = ANONYMOUSID;
tconn = rx_ConnectionOf(acall);
code = rx_SecurityClassOf(tconn);
if (code == 0)
return 0;
else if (code == 1) { /* vab class */
goto done; /* no longer supported */
} else if (code == 2) { /* kad class */
if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
name, inst, tcell, NULL)))
goto done;
#if 0
/* This test is unnecessary, since rxkad_GetServerInfo already check.
* In addition, this is wrong since exp must be unsigned. */
if (exp < FT_ApproxTime())
goto done;
#endif
if (tcell[0])
foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
strncpy(vname, name, sizeof(vname));
if ((ilen = strlen(inst))) {
if (strlen(vname) + 1 + ilen >= sizeof(vname))
goto done;
strcat(vname, ".");
strcat(vname, inst);
}
if (foreign) {
if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
goto done;
strcat(vname, "@");
strcat(vname, tcell);
}
if (strcmp(AUTH_SUPERUSER, vname) == 0)
*aid = SYSADMINID; /* special case for the fileserver */
else {
lcstring(vname, vname, sizeof(vname));
code = NameToID(at, vname, aid);
}
}
done:
if (code && !pr_noAuth)
return -1;
return 0;
}
| Bypass | 0 | WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid)
{
int foreign = 0;
/* aid is set to the identity of the caller, if known, else ANONYMOUSID */
/* returns -1 and sets aid to ANONYMOUSID on any failure */
struct rx_connection *tconn;
afs_int32 code;
char tcell[MAXKTCREALMLEN];
char name[MAXKTCNAMELEN];
char inst[MAXKTCNAMELEN];
int ilen;
char vname[256];
*aid = ANONYMOUSID;
tconn = rx_ConnectionOf(acall);
code = rx_SecurityClassOf(tconn);
if (code == 0)
return 0;
else if (code == 1) { /* vab class */
goto done; /* no longer supported */
} else if (code == 2) { /* kad class */
if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
name, inst, tcell, NULL)))
goto done;
#if 0
/* This test is unnecessary, since rxkad_GetServerInfo already check.
* In addition, this is wrong since exp must be unsigned. */
if (exp < FT_ApproxTime())
goto done;
#endif
if (tcell[0])
foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
strncpy(vname, name, sizeof(vname));
if ((ilen = strlen(inst))) {
if (strlen(vname) + 1 + ilen >= sizeof(vname))
goto done;
strcat(vname, ".");
strcat(vname, inst);
}
if (foreign) {
if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
goto done;
strcat(vname, "@");
strcat(vname, tcell);
}
if (strcmp(AUTH_SUPERUSER, vname) == 0)
*aid = SYSADMINID; /* special case for the fileserver */
else {
lcstring(vname, vname, sizeof(vname));
code = NameToID(at, vname, aid);
}
}
done:
if (code && !pr_noAuth)
return -1;
return 0;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,012 | WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
char *aname)
{
/* aid is set to the identity of the caller, if known, else ANONYMOUSID */
/* returns -1 and sets aid to ANONYMOUSID on any failure */
struct rx_connection *tconn;
afs_int32 code;
char tcell[MAXKTCREALMLEN];
char name[MAXKTCNAMELEN];
char inst[MAXKTCNAMELEN];
int ilen;
char vname[256];
*aid = ANONYMOUSID;
tconn = rx_ConnectionOf(acall);
code = rx_SecurityClassOf(tconn);
if (code == 0)
return 0;
else if (code == 1) { /* vab class */
goto done; /* no longer supported */
} else if (code == 2) { /* kad class */
int clen;
if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
name, inst, tcell, NULL)))
goto done;
strncpy(vname, name, sizeof(vname));
if ((ilen = strlen(inst))) {
if (strlen(vname) + 1 + ilen >= sizeof(vname))
goto done;
strcat(vname, ".");
strcat(vname, inst);
}
if ((clen = strlen(tcell))) {
int foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
if (foreign) {
if (strlen(vname) + 1 + clen >= sizeof(vname))
goto done;
strcat(vname, "@");
strcat(vname, tcell);
lcstring(vname, vname, sizeof(vname));
code = NameToID(at, vname, aid);
strcpy(aname, vname);
return 2;
}
}
if (strcmp(AUTH_SUPERUSER, vname) == 0)
*aid = SYSADMINID; /* special case for the fileserver */
else {
lcstring(vname, vname, sizeof(vname));
code = NameToID(at, vname, aid);
}
}
done:
if (code && !pr_noAuth)
return -1;
return 0;
}
| Bypass | 0 | WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
char *aname)
{
/* aid is set to the identity of the caller, if known, else ANONYMOUSID */
/* returns -1 and sets aid to ANONYMOUSID on any failure */
struct rx_connection *tconn;
afs_int32 code;
char tcell[MAXKTCREALMLEN];
char name[MAXKTCNAMELEN];
char inst[MAXKTCNAMELEN];
int ilen;
char vname[256];
*aid = ANONYMOUSID;
tconn = rx_ConnectionOf(acall);
code = rx_SecurityClassOf(tconn);
if (code == 0)
return 0;
else if (code == 1) { /* vab class */
goto done; /* no longer supported */
} else if (code == 2) { /* kad class */
int clen;
if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ ,
name, inst, tcell, NULL)))
goto done;
strncpy(vname, name, sizeof(vname));
if ((ilen = strlen(inst))) {
if (strlen(vname) + 1 + ilen >= sizeof(vname))
goto done;
strcat(vname, ".");
strcat(vname, inst);
}
if ((clen = strlen(tcell))) {
int foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName);
if (foreign) {
if (strlen(vname) + 1 + clen >= sizeof(vname))
goto done;
strcat(vname, "@");
strcat(vname, tcell);
lcstring(vname, vname, sizeof(vname));
code = NameToID(at, vname, aid);
strcpy(aname, vname);
return 2;
}
}
if (strcmp(AUTH_SUPERUSER, vname) == 0)
*aid = SYSADMINID; /* special case for the fileserver */
else {
lcstring(vname, vname, sizeof(vname));
code = NameToID(at, vname, aid);
}
}
done:
if (code && !pr_noAuth)
return -1;
return 0;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,013 | addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 tempu;
afs_int32 tempg;
struct prentry tentry;
struct prentry uentry;
code = Initdb();
if (code != PRSUCCESS)
return code;
if (gid == ANYUSERID || gid == AUTHUSERID)
return PRPERM;
if (aid == ANONYMOUSID)
return PRPERM;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
tempu = FindByID(tt, aid);
if (!tempu)
ABORT_WITH(tt, PRNOENT);
memset(&uentry, 0, sizeof(uentry));
code = pr_ReadEntry(tt, 0, tempu, &uentry);
if (code != 0)
ABORT_WITH(tt, code);
#if !defined(SUPERGROUPS)
/* we don't allow groups as members of groups at present */
if (uentry.flags & PRGRP)
ABORT_WITH(tt, PRNOTUSER);
#endif
tempg = FindByID(tt, gid);
if (!tempg)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, tempg, &tentry);
if (code != 0)
ABORT_WITH(tt, code);
/* make sure that this is a group */
if (!(tentry.flags & PRGRP))
ABORT_WITH(tt, PRNOTGROUP);
if (!AccessOK(tt, *cid, &tentry, PRP_ADD_MEM, PRP_ADD_ANY))
ABORT_WITH(tt, PRPERM);
code = AddToEntry(tt, &tentry, tempg, aid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
#if defined(SUPERGROUPS)
if (uentry.flags & PRGRP)
code = AddToSGEntry(tt, &uentry, tempu, gid); /* mod group to be in sg */
else
#endif
/* now, modify the user's entry as well */
code = AddToEntry(tt, &uentry, tempu, gid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 tempu;
afs_int32 tempg;
struct prentry tentry;
struct prentry uentry;
code = Initdb();
if (code != PRSUCCESS)
return code;
if (gid == ANYUSERID || gid == AUTHUSERID)
return PRPERM;
if (aid == ANONYMOUSID)
return PRPERM;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
tempu = FindByID(tt, aid);
if (!tempu)
ABORT_WITH(tt, PRNOENT);
memset(&uentry, 0, sizeof(uentry));
code = pr_ReadEntry(tt, 0, tempu, &uentry);
if (code != 0)
ABORT_WITH(tt, code);
#if !defined(SUPERGROUPS)
/* we don't allow groups as members of groups at present */
if (uentry.flags & PRGRP)
ABORT_WITH(tt, PRNOTUSER);
#endif
tempg = FindByID(tt, gid);
if (!tempg)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, tempg, &tentry);
if (code != 0)
ABORT_WITH(tt, code);
/* make sure that this is a group */
if (!(tentry.flags & PRGRP))
ABORT_WITH(tt, PRNOTGROUP);
if (!AccessOK(tt, *cid, &tentry, PRP_ADD_MEM, PRP_ADD_ANY))
ABORT_WITH(tt, PRPERM);
code = AddToEntry(tt, &tentry, tempg, aid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
#if defined(SUPERGROUPS)
if (uentry.flags & PRGRP)
code = AddToSGEntry(tt, &uentry, tempu, gid); /* mod group to be in sg */
else
#endif
/* now, modify the user's entry as well */
code = AddToEntry(tt, &uentry, tempu, gid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,014 | addWildCards(struct ubik_trans *tt, prlist *alist, afs_uint32 host)
{
afs_int32 temp;
struct prentry tentry;
prlist wlist;
unsigned wild = htonl(0xffffff00);
struct in_addr iaddr;
afs_int32 hostid;
int size = 0, i, code;
int added = 0;
char hoststr[16];
while ((host = (host & wild))) {
wild = htonl(ntohl(wild) << 8);
iaddr.s_addr = host;
code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code != PRSUCCESS)
continue;
} else
continue;
} else
continue;
wlist.prlist_len = 0;
wlist.prlist_val = NULL;
code = GetList(tt, &tentry, &wlist, 0);
if (code)
return code;
added += wlist.prlist_len;
for (i = 0; i < wlist.prlist_len; i++) {
if (!inCPS(*alist, wlist.prlist_val[i]))
if ((code = AddToPRList(alist, &size, wlist.prlist_val[i]))) {
free(wlist.prlist_val);
return (code);
}
}
if (wlist.prlist_val)
free(wlist.prlist_val);
}
if (added)
qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
return 0;
}
| Bypass | 0 | addWildCards(struct ubik_trans *tt, prlist *alist, afs_uint32 host)
{
afs_int32 temp;
struct prentry tentry;
prlist wlist;
unsigned wild = htonl(0xffffff00);
struct in_addr iaddr;
afs_int32 hostid;
int size = 0, i, code;
int added = 0;
char hoststr[16];
while ((host = (host & wild))) {
wild = htonl(ntohl(wild) << 8);
iaddr.s_addr = host;
code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code != PRSUCCESS)
continue;
} else
continue;
} else
continue;
wlist.prlist_len = 0;
wlist.prlist_val = NULL;
code = GetList(tt, &tentry, &wlist, 0);
if (code)
return code;
added += wlist.prlist_len;
for (i = 0; i < wlist.prlist_len; i++) {
if (!inCPS(*alist, wlist.prlist_val[i]))
if ((code = AddToPRList(alist, &size, wlist.prlist_val[i]))) {
free(wlist.prlist_val);
return (code);
}
}
if (wlist.prlist_val)
free(wlist.prlist_val);
}
if (added)
qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
return 0;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,015 | getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
*over = 0;
alist->prlist_len = 0;
alist->prlist_val = NULL;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
/* afs does authenticate now */
code = WhoIsThis(call, tt, cid);
if (code || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
code = GetList(tt, &tentry, alist, 1);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| Bypass | 0 | getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
*over = 0;
alist->prlist_len = 0;
alist->prlist_val = NULL;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
/* afs does authenticate now */
code = WhoIsThis(call, tt, cid);
if (code || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
code = GetList(tt, &tentry, alist, 1);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,016 | getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost, prlist *alist,
afs_int32 *over, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
struct prentry host_tentry;
afs_int32 hostid;
int host_list = 0;
struct in_addr iaddr;
char hoststr[16];
*over = 0;
iaddr.s_addr = ntohl(ahost);
alist->prlist_len = 0;
alist->prlist_val = NULL;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
if (aid != PRBADID) {
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
/* afs does authenticate now */
code = WhoIsThis(call, tt, cid);
if (code
|| !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
}
code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
code = pr_ReadEntry(tt, 0, temp, &host_tentry);
if (code == PRSUCCESS)
host_list = 1;
else
fprintf(stderr, "pr_ReadEntry returned %d\n", code);
} else
fprintf(stderr, "FindByID Failed -- Not found\n");
}
if (host_list)
code = GetList2(tt, &tentry, &host_tentry, alist, 1);
else
code = GetList(tt, &tentry, alist, 1);
if (!code)
code = addWildCards(tt, alist, ntohl(ahost));
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| Bypass | 0 | getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost, prlist *alist,
afs_int32 *over, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
struct prentry host_tentry;
afs_int32 hostid;
int host_list = 0;
struct in_addr iaddr;
char hoststr[16];
*over = 0;
iaddr.s_addr = ntohl(ahost);
alist->prlist_len = 0;
alist->prlist_val = NULL;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
if (aid != PRBADID) {
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
/* afs does authenticate now */
code = WhoIsThis(call, tt, cid);
if (code
|| !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
}
code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
code = pr_ReadEntry(tt, 0, temp, &host_tentry);
if (code == PRSUCCESS)
host_list = 1;
else
fprintf(stderr, "pr_ReadEntry returned %d\n", code);
} else
fprintf(stderr, "FindByID Failed -- Not found\n");
}
if (host_list)
code = GetList2(tt, &tentry, &host_tentry, alist, 1);
else
code = GetList(tt, &tentry, alist, 1);
if (!code)
code = addWildCards(tt, alist, ntohl(ahost));
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,017 | iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid,
afs_int32 *cid)
{
/* used primarily for conversion - not intended to be used as usual means
* of entering people into the database. */
struct ubik_trans *tt;
afs_int32 code;
afs_int32 gflag = 0;
int admin;
stolower(aname);
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
admin = IsAMemberOf(tt, *cid, SYSADMINID);
/* first verify the id is good */
if (aid == 0)
ABORT_WITH(tt, PRPERM);
if (aid < 0) {
gflag |= PRGRP;
/* only sysadmin can reuse a group id */
if (!admin && !pr_noAuth && (aid != ntohl(cheader.maxGroup) - 1))
ABORT_WITH(tt, PRPERM);
}
if (FindByID(tt, aid))
ABORT_WITH(tt, PRIDEXIST);
/* check a few other things */
if (!CreateOK(tt, *cid, oid, gflag, admin))
ABORT_WITH(tt, PRPERM);
code = CreateEntry(tt, aname, &aid, 1, gflag, oid, *cid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
/* finally, commit transaction */
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid,
afs_int32 *cid)
{
/* used primarily for conversion - not intended to be used as usual means
* of entering people into the database. */
struct ubik_trans *tt;
afs_int32 code;
afs_int32 gflag = 0;
int admin;
stolower(aname);
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
admin = IsAMemberOf(tt, *cid, SYSADMINID);
/* first verify the id is good */
if (aid == 0)
ABORT_WITH(tt, PRPERM);
if (aid < 0) {
gflag |= PRGRP;
/* only sysadmin can reuse a group id */
if (!admin && !pr_noAuth && (aid != ntohl(cheader.maxGroup) - 1))
ABORT_WITH(tt, PRPERM);
}
if (FindByID(tt, aid))
ABORT_WITH(tt, PRIDEXIST);
/* check a few other things */
if (!CreateOK(tt, *cid, oid, gflag, admin))
ABORT_WITH(tt, PRPERM);
code = CreateEntry(tt, aname, &aid, 1, gflag, oid, *cid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
/* finally, commit transaction */
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,018 | idToName(struct rx_call *call, idlist *aid, namelist *aname)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 i;
int size;
int count = 0;
/* leave this first for rpc stub */
size = aid->idlist_len;
if (size == 0)
return 0;
if (size < 0 || size > INT_MAX / PR_MAXNAMELEN)
return PRTOOMANY;
aname->namelist_val = (prname *) malloc(size * PR_MAXNAMELEN);
aname->namelist_len = 0;
if (aname->namelist_val == 0)
return PRNOMEM;
if (aid->idlist_len == 0)
return 0;
if (size == 0)
return PRTOOMANY; /* rxgen will probably handle this */
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
for (i = 0; i < aid->idlist_len; i++) {
code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
if (code != PRSUCCESS)
sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
osi_audit(PTS_IdToNmEvent, code, AUD_ID, aid->idlist_val[i],
AUD_STR, aname->namelist_val[i], AUD_END);
ViceLog(125, ("PTS_idToName: code %d aid %d aname %s\n", code,
aid->idlist_val[i], aname->namelist_val[i]));
if (count++ > 50) {
#ifndef AFS_PTHREAD_ENV
IOMGR_Poll();
#endif
count = 0;
}
}
aname->namelist_len = aid->idlist_len;
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | idToName(struct rx_call *call, idlist *aid, namelist *aname)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 i;
int size;
int count = 0;
/* leave this first for rpc stub */
size = aid->idlist_len;
if (size == 0)
return 0;
if (size < 0 || size > INT_MAX / PR_MAXNAMELEN)
return PRTOOMANY;
aname->namelist_val = (prname *) malloc(size * PR_MAXNAMELEN);
aname->namelist_len = 0;
if (aname->namelist_val == 0)
return PRNOMEM;
if (aid->idlist_len == 0)
return 0;
if (size == 0)
return PRTOOMANY; /* rxgen will probably handle this */
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
for (i = 0; i < aid->idlist_len; i++) {
code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
if (code != PRSUCCESS)
sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
osi_audit(PTS_IdToNmEvent, code, AUD_ID, aid->idlist_val[i],
AUD_STR, aname->namelist_val[i], AUD_END);
ViceLog(125, ("PTS_idToName: code %d aid %d aname %s\n", code,
aid->idlist_val[i], aname->namelist_val[i]));
if (count++ > 50) {
#ifndef AFS_PTHREAD_ENV
IOMGR_Poll();
#endif
count = 0;
}
}
aname->namelist_len = aid->idlist_len;
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,019 | inCPS(prlist CPS, afs_int32 id)
{
int i;
for (i = (CPS.prlist_len - 1); i >= 0; i--) {
if (CPS.prlist_val[i] == id)
return (1);
}
return (0);
}
| Bypass | 0 | inCPS(prlist CPS, afs_int32 id)
{
int i;
for (i = (CPS.prlist_len - 1); i >= 0; i--) {
if (CPS.prlist_val[i] == id)
return (1);
}
return (0);
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,020 | isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
{
afs_int32 uloc = FindByID(tt, uid);
afs_int32 gloc = FindByID(tt, gid);
struct prentry uentry, gentry;
if (!uloc || !gloc)
ABORT_WITH(tt, PRNOENT);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
code = pr_ReadEntry(tt, 0, uloc, &uentry);
if (code)
ABORT_WITH(tt, code);
code = pr_ReadEntry(tt, 0, gloc, &gentry);
if (code)
ABORT_WITH(tt, code);
#if !defined(SUPERGROUPS)
if ((uentry.flags & PRGRP) || !(gentry.flags & PRGRP))
ABORT_WITH(tt, PRBADARG);
#else
if (!(gentry.flags & PRGRP))
ABORT_WITH(tt, PRBADARG);
#endif
if (!AccessOK(tt, *cid, &uentry, 0, PRP_MEMBER_ANY)
&& !AccessOK(tt, *cid, &gentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
}
*flag = IsAMemberOf(tt, uid, gid);
code = ubik_EndTrans(tt);
return code;
}
| Bypass | 0 | isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
{
afs_int32 uloc = FindByID(tt, uid);
afs_int32 gloc = FindByID(tt, gid);
struct prentry uentry, gentry;
if (!uloc || !gloc)
ABORT_WITH(tt, PRNOENT);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
code = pr_ReadEntry(tt, 0, uloc, &uentry);
if (code)
ABORT_WITH(tt, code);
code = pr_ReadEntry(tt, 0, gloc, &gentry);
if (code)
ABORT_WITH(tt, code);
#if !defined(SUPERGROUPS)
if ((uentry.flags & PRGRP) || !(gentry.flags & PRGRP))
ABORT_WITH(tt, PRBADARG);
#else
if (!(gentry.flags & PRGRP))
ABORT_WITH(tt, PRBADARG);
#endif
if (!AccessOK(tt, *cid, &uentry, 0, PRP_MEMBER_ANY)
&& !AccessOK(tt, *cid, &gentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
}
*flag = IsAMemberOf(tt, uid, gid);
code = ubik_EndTrans(tt);
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,021 | listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *over, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
*over = 0;
alist->prlist_len = 0;
alist->prlist_val = NULL;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
code = GetList(tt, &tentry, alist, 0);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| Bypass | 0 | listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *over, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
*over = 0;
alist->prlist_len = 0;
alist->prlist_val = NULL;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
code = GetList(tt, &tentry, alist, 0);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,022 | listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 i, eof, pos, maxentries, f;
struct prentry tentry;
afs_int32 pollcount = 0;
*nextstartindex = -1;
bulkentries->prentries_val = 0;
bulkentries->prentries_len = 0;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
/* Make sure we are an authenticated caller and that we are on the
* SYSADMIN list.
*/
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
code = IsAMemberOf(tt, *cid, SYSADMINID);
if (!code && !pr_noAuth)
ABORT_WITH(tt, PRPERM);
eof = ntohl(cheader.eofPtr) - sizeof(cheader);
maxentries = eof / sizeof(struct prentry);
for (i = startindex; i < maxentries; i++) {
pos = i * sizeof(struct prentry) + sizeof(cheader);
code = pr_ReadEntry(tt, 0, pos, &tentry);
if (code)
goto done;
if (++pollcount > 50) {
#ifndef AFS_PTHREAD_ENV
IOMGR_Poll();
#endif
pollcount = 0;
}
f = (tentry.flags & PRTYPE);
if (((flag & PRUSERS) && (f == 0)) || /* User entry */
((flag & PRGROUPS) && (f & PRGRP))) { /* Group entry */
code = put_prentries(&tentry, bulkentries);
if (code == -1)
break; /* Filled return array */
if (code)
goto done;
}
}
code = 0;
if (i < maxentries)
*nextstartindex = i;
done:
if (code) {
if (bulkentries->prentries_val)
free(bulkentries->prentries_val);
bulkentries->prentries_val = 0;
bulkentries->prentries_len = 0;
ABORT_WITH(tt, code);
} else {
code = ubik_EndTrans(tt);
}
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 i, eof, pos, maxentries, f;
struct prentry tentry;
afs_int32 pollcount = 0;
*nextstartindex = -1;
bulkentries->prentries_val = 0;
bulkentries->prentries_len = 0;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
/* Make sure we are an authenticated caller and that we are on the
* SYSADMIN list.
*/
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
code = IsAMemberOf(tt, *cid, SYSADMINID);
if (!code && !pr_noAuth)
ABORT_WITH(tt, PRPERM);
eof = ntohl(cheader.eofPtr) - sizeof(cheader);
maxentries = eof / sizeof(struct prentry);
for (i = startindex; i < maxentries; i++) {
pos = i * sizeof(struct prentry) + sizeof(cheader);
code = pr_ReadEntry(tt, 0, pos, &tentry);
if (code)
goto done;
if (++pollcount > 50) {
#ifndef AFS_PTHREAD_ENV
IOMGR_Poll();
#endif
pollcount = 0;
}
f = (tentry.flags & PRTYPE);
if (((flag & PRUSERS) && (f == 0)) || /* User entry */
((flag & PRGROUPS) && (f & PRGRP))) { /* Group entry */
code = put_prentries(&tentry, bulkentries);
if (code == -1)
break; /* Filled return array */
if (code)
goto done;
}
}
code = 0;
if (i < maxentries)
*nextstartindex = i;
done:
if (code) {
if (bulkentries->prentries_val)
free(bulkentries->prentries_val);
bulkentries->prentries_val = 0;
bulkentries->prentries_len = 0;
ABORT_WITH(tt, code);
} else {
code = ubik_EndTrans(tt);
}
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,023 | listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code != 0)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, PRP_STATUS_MEM, PRP_STATUS_ANY))
ABORT_WITH(tt, PRPERM);
aentry->flags = tentry.flags >> PRIVATE_SHIFT;
if (aentry->flags == 0) {
if (tentry.flags & PRGRP)
aentry->flags = prp_group_default >> PRIVATE_SHIFT;
else
aentry->flags = prp_user_default >> PRIVATE_SHIFT;
}
aentry->owner = tentry.owner;
aentry->id = tentry.id;
strncpy(aentry->name, tentry.name, PR_MAXNAMELEN);
aentry->creator = tentry.creator;
aentry->ngroups = tentry.ngroups;
aentry->nusers = tentry.nusers;
aentry->count = tentry.count;
memset(aentry->reserved, 0, sizeof(aentry->reserved));
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code != 0)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, PRP_STATUS_MEM, PRP_STATUS_ANY))
ABORT_WITH(tt, PRPERM);
aentry->flags = tentry.flags >> PRIVATE_SHIFT;
if (aentry->flags == 0) {
if (tentry.flags & PRGRP)
aentry->flags = prp_group_default >> PRIVATE_SHIFT;
else
aentry->flags = prp_user_default >> PRIVATE_SHIFT;
}
aentry->owner = tentry.owner;
aentry->id = tentry.id;
strncpy(aentry->name, tentry.name, PR_MAXNAMELEN);
aentry->creator = tentry.creator;
aentry->ngroups = tentry.ngroups;
aentry->nusers = tentry.nusers;
aentry->count = tentry.count;
memset(aentry->reserved, 0, sizeof(aentry->reserved));
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,024 | listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
struct prentry tentry;
afs_int32 head = 0;
afs_int32 start;
alist->prlist_len = 0;
alist->prlist_val = NULL;
if (!lastP)
return PRBADARG;
start = *lastP;
*lastP = 0;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
if (start) {
code = pr_ReadEntry(tt, 0, start, &tentry);
if (!code && (tentry.owner == aid))
head = start; /* pick up where we left off */
}
if (!head) {
if (aid) {
afs_int32 loc = FindByID(tt, aid);
if (loc == 0)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, loc, &tentry);
if (code)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, -1, PRP_OWNED_ANY))
ABORT_WITH(tt, PRPERM);
head = tentry.owned;
} else {
if (!AccessOK(tt, *cid, 0, 0, 0))
ABORT_WITH(tt, PRPERM);
head = ntohl(cheader.orphan);
}
}
code = GetOwnedChain(tt, &head, alist);
if (code) {
if (code == PRTOOMANY)
*lastP = head;
else
ABORT_WITH(tt, code);
}
code = ubik_EndTrans(tt);
return code;
}
| Bypass | 0 | listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
struct prentry tentry;
afs_int32 head = 0;
afs_int32 start;
alist->prlist_len = 0;
alist->prlist_val = NULL;
if (!lastP)
return PRBADARG;
start = *lastP;
*lastP = 0;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
if (start) {
code = pr_ReadEntry(tt, 0, start, &tentry);
if (!code && (tentry.owner == aid))
head = start; /* pick up where we left off */
}
if (!head) {
if (aid) {
afs_int32 loc = FindByID(tt, aid);
if (loc == 0)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, loc, &tentry);
if (code)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, -1, PRP_OWNED_ANY))
ABORT_WITH(tt, PRPERM);
head = tentry.owned;
} else {
if (!AccessOK(tt, *cid, 0, 0, 0))
ABORT_WITH(tt, PRPERM);
head = ntohl(cheader.orphan);
}
}
code = GetOwnedChain(tt, &head, alist);
if (code) {
if (code == PRTOOMANY)
*lastP = head;
else
ABORT_WITH(tt, code);
}
code = ubik_EndTrans(tt);
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,025 | listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *over, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
alist->prlist_len = 0;
alist->prlist_val = (afs_int32 *) 0;
code = Initdb();
if (code != PRSUCCESS)
goto done;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
goto done;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
code = GetSGList(tt, &tentry, alist);
*over = 0;
if (code == PRTOOMANY)
*over = 1;
else if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
done:
return code;
}
| Bypass | 0 | listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
afs_int32 *over, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
struct prentry tentry;
alist->prlist_len = 0;
alist->prlist_val = (afs_int32 *) 0;
code = Initdb();
if (code != PRSUCCESS)
goto done;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
goto done;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, temp, &tentry);
if (code)
ABORT_WITH(tt, code);
if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
code = GetSGList(tt, &tentry, alist);
*over = 0;
if (code == PRTOOMANY)
*over = 1;
else if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
done:
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,026 | nameToID(struct rx_call *call, namelist *aname, idlist *aid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 i;
int size;
int count = 0;
/* Initialize return struct */
aid->idlist_len = 0;
aid->idlist_val = NULL;
size = aname->namelist_len;
if (size == 0)
return 0;
if (size < 0)
return PRTOOMANY;
aid->idlist_val = (afs_int32 *) malloc(size * sizeof(afs_int32));
if (!aid->idlist_val)
return PRNOMEM;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
for (i = 0; i < aname->namelist_len; i++) {
char vname[256];
char *nameinst, *cell;
strncpy(vname, aname->namelist_val[i], sizeof(vname));
vname[sizeof(vname)-1] ='\0';
nameinst = vname;
cell = strchr(vname, '@');
if (cell) {
*cell = '\0';
cell++;
}
if (cell && afs_is_foreign_ticket_name(nameinst,NULL,cell,pr_realmName))
code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
else
code = NameToID(tt, nameinst, &aid->idlist_val[i]);
if (code != PRSUCCESS)
aid->idlist_val[i] = ANONYMOUSID;
osi_audit(PTS_NmToIdEvent, code, AUD_STR,
aname->namelist_val[i], AUD_ID, aid->idlist_val[i],
AUD_END);
ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d\n", code,
aname->namelist_val[i], aid->idlist_val[i]));
if (count++ > 50) {
#ifndef AFS_PTHREAD_ENV
IOMGR_Poll();
#endif
count = 0;
}
}
aid->idlist_len = aname->namelist_len;
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | nameToID(struct rx_call *call, namelist *aname, idlist *aid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 i;
int size;
int count = 0;
/* Initialize return struct */
aid->idlist_len = 0;
aid->idlist_val = NULL;
size = aname->namelist_len;
if (size == 0)
return 0;
if (size < 0)
return PRTOOMANY;
aid->idlist_val = (afs_int32 *) malloc(size * sizeof(afs_int32));
if (!aid->idlist_val)
return PRNOMEM;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
for (i = 0; i < aname->namelist_len; i++) {
char vname[256];
char *nameinst, *cell;
strncpy(vname, aname->namelist_val[i], sizeof(vname));
vname[sizeof(vname)-1] ='\0';
nameinst = vname;
cell = strchr(vname, '@');
if (cell) {
*cell = '\0';
cell++;
}
if (cell && afs_is_foreign_ticket_name(nameinst,NULL,cell,pr_realmName))
code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
else
code = NameToID(tt, nameinst, &aid->idlist_val[i]);
if (code != PRSUCCESS)
aid->idlist_val[i] = ANONYMOUSID;
osi_audit(PTS_NmToIdEvent, code, AUD_STR,
aname->namelist_val[i], AUD_ID, aid->idlist_val[i],
AUD_END);
ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d\n", code,
aname->namelist_val[i], aid->idlist_val[i]));
if (count++ > 50) {
#ifndef AFS_PTHREAD_ENV
IOMGR_Poll();
#endif
count = 0;
}
}
aid->idlist_len = aname->namelist_len;
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,027 | put_prentries(struct prentry *tentry, prentries *bulkentries)
{
struct prlistentries *entry;
if (bulkentries->prentries_val == 0) {
bulkentries->prentries_len = 0;
bulkentries->prentries_val =
(struct prlistentries *)malloc(PR_MAXENTRIES *
sizeof(struct prentry));
if (!bulkentries->prentries_val) {
return (PRNOMEM);
}
}
if (bulkentries->prentries_len >= PR_MAXENTRIES) {
return (-1);
}
entry = (struct prlistentries *)bulkentries->prentries_val;
entry += bulkentries->prentries_len;
entry->flags = tentry->flags >> PRIVATE_SHIFT;
if (entry->flags == 0) {
entry->flags =
((tentry->
flags & PRGRP) ? prp_group_default : prp_user_default) >>
PRIVATE_SHIFT;
}
entry->owner = tentry->owner;
entry->id = tentry->id;
entry->creator = tentry->creator;
entry->ngroups = tentry->ngroups;
entry->nusers = tentry->nusers;
entry->count = tentry->count;
strncpy(entry->name, tentry->name, PR_MAXNAMELEN);
memset(entry->reserved, 0, sizeof(entry->reserved));
bulkentries->prentries_len++;
return 0;
}
| Bypass | 0 | put_prentries(struct prentry *tentry, prentries *bulkentries)
{
struct prlistentries *entry;
if (bulkentries->prentries_val == 0) {
bulkentries->prentries_len = 0;
bulkentries->prentries_val =
(struct prlistentries *)malloc(PR_MAXENTRIES *
sizeof(struct prentry));
if (!bulkentries->prentries_val) {
return (PRNOMEM);
}
}
if (bulkentries->prentries_len >= PR_MAXENTRIES) {
return (-1);
}
entry = (struct prlistentries *)bulkentries->prentries_val;
entry += bulkentries->prentries_len;
entry->flags = tentry->flags >> PRIVATE_SHIFT;
if (entry->flags == 0) {
entry->flags =
((tentry->
flags & PRGRP) ? prp_group_default : prp_user_default) >>
PRIVATE_SHIFT;
}
entry->owner = tentry->owner;
entry->id = tentry->id;
entry->creator = tentry->creator;
entry->ngroups = tentry->ngroups;
entry->nusers = tentry->nusers;
entry->count = tentry->count;
strncpy(entry->name, tentry->name, PR_MAXNAMELEN);
memset(entry->reserved, 0, sizeof(entry->reserved));
bulkentries->prentries_len++;
return 0;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,028 | removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 tempu;
afs_int32 tempg;
struct prentry uentry;
struct prentry gentry;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
tempu = FindByID(tt, aid);
if (!tempu)
ABORT_WITH(tt, PRNOENT);
tempg = FindByID(tt, gid);
if (!tempg)
ABORT_WITH(tt, PRNOENT);
memset(&uentry, 0, sizeof(uentry));
memset(&gentry, 0, sizeof(gentry));
code = pr_ReadEntry(tt, 0, tempu, &uentry);
if (code != 0)
ABORT_WITH(tt, code);
code = pr_ReadEntry(tt, 0, tempg, &gentry);
if (code != 0)
ABORT_WITH(tt, code);
if (!(gentry.flags & PRGRP))
ABORT_WITH(tt, PRNOTGROUP);
#if !defined(SUPERGROUPS)
if (uentry.flags & PRGRP)
ABORT_WITH(tt, PRNOTUSER);
#endif
if (!AccessOK(tt, *cid, &gentry, PRP_REMOVE_MEM, 0))
ABORT_WITH(tt, PRPERM);
code = RemoveFromEntry(tt, aid, gid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
#if defined(SUPERGROUPS)
if (!(uentry.flags & PRGRP))
#endif
code = RemoveFromEntry(tt, gid, aid);
#if defined(SUPERGROUPS)
else
code = RemoveFromSGEntry(tt, gid, aid);
#endif
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 tempu;
afs_int32 tempg;
struct prentry uentry;
struct prentry gentry;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
tempu = FindByID(tt, aid);
if (!tempu)
ABORT_WITH(tt, PRNOENT);
tempg = FindByID(tt, gid);
if (!tempg)
ABORT_WITH(tt, PRNOENT);
memset(&uentry, 0, sizeof(uentry));
memset(&gentry, 0, sizeof(gentry));
code = pr_ReadEntry(tt, 0, tempu, &uentry);
if (code != 0)
ABORT_WITH(tt, code);
code = pr_ReadEntry(tt, 0, tempg, &gentry);
if (code != 0)
ABORT_WITH(tt, code);
if (!(gentry.flags & PRGRP))
ABORT_WITH(tt, PRNOTGROUP);
#if !defined(SUPERGROUPS)
if (uentry.flags & PRGRP)
ABORT_WITH(tt, PRNOTUSER);
#endif
if (!AccessOK(tt, *cid, &gentry, PRP_REMOVE_MEM, 0))
ABORT_WITH(tt, PRPERM);
code = RemoveFromEntry(tt, aid, gid);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
#if defined(SUPERGROUPS)
if (!(uentry.flags & PRGRP))
#endif
code = RemoveFromEntry(tt, gid, aid);
#if defined(SUPERGROUPS)
else
code = RemoveFromSGEntry(tt, gid, aid);
#endif
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,029 | setFieldsEntry(struct rx_call *call,
afs_int32 id,
afs_int32 mask, /* specify which fields to update */
afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
afs_int32 spare1, afs_int32 spare2, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 pos;
struct prentry tentry;
afs_int32 tflags;
if (mask == 0)
return 0; /* no-op */
code = Initdb();
if (code)
return code;
if (id == ANYUSERID || id == AUTHUSERID || id == ANONYMOUSID)
return PRPERM;
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
pos = FindByID(tt, id);
if (!pos)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, pos, &tentry);
if (code)
ABORT_WITH(tt, code);
tflags = tentry.flags;
if (mask & (PR_SF_NGROUPS | PR_SF_NUSERS)) {
if (!AccessOK(tt, *cid, 0, 0, 0))
ABORT_WITH(tt, PRPERM);
if ((tflags & PRQUOTA) == 0) { /* default if only setting one */
tentry.ngroups = tentry.nusers = 20;
}
} else {
if (!AccessOK(tt, *cid, &tentry, 0, 0))
ABORT_WITH(tt, PRPERM);
}
if (mask & 0xffff) { /* if setting flag bits */
afs_int32 flagsMask = mask & 0xffff;
tflags &= ~(flagsMask << PRIVATE_SHIFT);
tflags |= (flags & flagsMask) << PRIVATE_SHIFT;
tflags |= PRACCESS;
}
if (mask & PR_SF_NGROUPS) { /* setting group limit */
if (ngroups < 0)
ABORT_WITH(tt, PRBADARG);
tentry.ngroups = ngroups;
tflags |= PRQUOTA;
}
if (mask & PR_SF_NUSERS) { /* setting foreign user limit */
if (nusers < 0)
ABORT_WITH(tt, PRBADARG);
tentry.nusers = nusers;
tflags |= PRQUOTA;
}
tentry.flags = tflags;
code = pr_WriteEntry(tt, 0, pos, &tentry);
if (code)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| Bypass | 0 | setFieldsEntry(struct rx_call *call,
afs_int32 id,
afs_int32 mask, /* specify which fields to update */
afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
afs_int32 spare1, afs_int32 spare2, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 pos;
struct prentry tentry;
afs_int32 tflags;
if (mask == 0)
return 0; /* no-op */
code = Initdb();
if (code)
return code;
if (id == ANYUSERID || id == AUTHUSERID || id == ANONYMOUSID)
return PRPERM;
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
pos = FindByID(tt, id);
if (!pos)
ABORT_WITH(tt, PRNOENT);
code = pr_ReadEntry(tt, 0, pos, &tentry);
if (code)
ABORT_WITH(tt, code);
tflags = tentry.flags;
if (mask & (PR_SF_NGROUPS | PR_SF_NUSERS)) {
if (!AccessOK(tt, *cid, 0, 0, 0))
ABORT_WITH(tt, PRPERM);
if ((tflags & PRQUOTA) == 0) { /* default if only setting one */
tentry.ngroups = tentry.nusers = 20;
}
} else {
if (!AccessOK(tt, *cid, &tentry, 0, 0))
ABORT_WITH(tt, PRPERM);
}
if (mask & 0xffff) { /* if setting flag bits */
afs_int32 flagsMask = mask & 0xffff;
tflags &= ~(flagsMask << PRIVATE_SHIFT);
tflags |= (flags & flagsMask) << PRIVATE_SHIFT;
tflags |= PRACCESS;
}
if (mask & PR_SF_NGROUPS) { /* setting group limit */
if (ngroups < 0)
ABORT_WITH(tt, PRBADARG);
tentry.ngroups = ngroups;
tflags |= PRQUOTA;
}
if (mask & PR_SF_NUSERS) { /* setting foreign user limit */
if (nusers < 0)
ABORT_WITH(tt, PRBADARG);
tentry.nusers = nusers;
tflags |= PRQUOTA;
}
tentry.flags = tflags;
code = pr_WriteEntry(tt, 0, pos, &tentry);
if (code)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
return code;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,030 | setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
if (!AccessOK(tt, *cid, 0, 0, 0))
ABORT_WITH(tt, PRPERM);
if (((gflag & PRGRP) && (aid > 0)) || (!(gflag & PRGRP) && (aid < 0)))
ABORT_WITH(tt, PRBADARG);
code = SetMax(tt, aid, gflag);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
if (!AccessOK(tt, *cid, 0, 0, 0))
ABORT_WITH(tt, PRPERM);
if (((gflag & PRGRP) && (aid > 0)) || (!(gflag & PRGRP) && (aid < 0)))
ABORT_WITH(tt, PRBADARG);
code = SetMax(tt, aid, gflag);
if (code != PRSUCCESS)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,031 | whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
*apos = temp;
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| Bypass | 0 | whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
{
afs_int32 code;
struct ubik_trans *tt;
afs_int32 temp;
code = Initdb();
if (code != PRSUCCESS)
return code;
code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
if (code)
return code;
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = read_DbHeader(tt);
if (code)
ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
ABORT_WITH(tt, PRPERM);
temp = FindByID(tt, aid);
if (!temp)
ABORT_WITH(tt, PRNOENT);
*apos = temp;
code = ubik_EndTrans(tt);
if (code)
return code;
return PRSUCCESS;
}
| @@ -345,13 +345,19 @@ newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
* automatic id assignment.
*/
code = WhoIsThisWithName(call, tt, cid, cname);
- if (code != 2) { /* 2 specifies that this is a foreign cell request */
- if (code)
- ABORT_WITH(tt, PRPERM);
- admin = IsAMemberOf(tt, *cid, SYSADMINID);
- } else {
- admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID);
- oid = *cid = SYSADMINID;
+ if (code && code != 2)
+ ABORT_WITH(tt, PRPERM);
+ admin = IsAMemberOf(tt, *cid, SYSADMINID);
+ if (code == 2 /* foreign cell request */) {
+ if (!restricted && (strcmp(aname, cname) == 0)) {
+ /* can't autoregister while providing an owner id */
+ if (oid != 0)
+ ABORT_WITH(tt, PRPERM);
+
+ admin = 1;
+ oid = SYSADMINID;
+ *cid = SYSADMINID;
+ }
}
if (!CreateOK(tt, *cid, oid, flag, admin))
ABORT_WITH(tt, PRPERM); | CWE-284 | null | null |
10,032 | static void register_types(void)
{
type_register_static(&rng_backend_info);
}
| DoS Overflow Mem. Corr. | 0 | static void register_types(void)
{
type_register_static(&rng_backend_info);
}
| @@ -20,9 +20,20 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,
void *opaque)
{
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
+ RngRequest *req;
if (k->request_entropy) {
- k->request_entropy(s, size, receive_entropy, opaque);
+ req = g_malloc(sizeof(*req));
+
+ req->offset = 0;
+ req->size = size;
+ req->receive_entropy = receive_entropy;
+ req->opaque = opaque;
+ req->data = g_malloc(req->size);
+
+ k->request_entropy(s, req);
+
+ s->requests = g_slist_append(s->requests, req);
}
} | CWE-119 | null | null |
10,033 | static void rng_backend_finalize(Object *obj)
{
RngBackend *s = RNG_BACKEND(obj);
rng_backend_free_requests(s);
}
| DoS Overflow Mem. Corr. | 0 | static void rng_backend_finalize(Object *obj)
{
RngBackend *s = RNG_BACKEND(obj);
rng_backend_free_requests(s);
}
| @@ -20,9 +20,20 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,
void *opaque)
{
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
+ RngRequest *req;
if (k->request_entropy) {
- k->request_entropy(s, size, receive_entropy, opaque);
+ req = g_malloc(sizeof(*req));
+
+ req->offset = 0;
+ req->size = size;
+ req->receive_entropy = receive_entropy;
+ req->opaque = opaque;
+ req->data = g_malloc(req->size);
+
+ k->request_entropy(s, req);
+
+ s->requests = g_slist_append(s->requests, req);
}
} | CWE-119 | null | null |
10,034 | static void rng_backend_free_requests(RngBackend *s)
{
GSList *i;
for (i = s->requests; i; i = i->next) {
rng_backend_free_request(i->data);
}
g_slist_free(s->requests);
s->requests = NULL;
}
| DoS Overflow Mem. Corr. | 0 | static void rng_backend_free_requests(RngBackend *s)
{
GSList *i;
for (i = s->requests; i; i = i->next) {
rng_backend_free_request(i->data);
}
g_slist_free(s->requests);
s->requests = NULL;
}
| @@ -20,9 +20,20 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,
void *opaque)
{
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
+ RngRequest *req;
if (k->request_entropy) {
- k->request_entropy(s, size, receive_entropy, opaque);
+ req = g_malloc(sizeof(*req));
+
+ req->offset = 0;
+ req->size = size;
+ req->receive_entropy = receive_entropy;
+ req->opaque = opaque;
+ req->data = g_malloc(req->size);
+
+ k->request_entropy(s, req);
+
+ s->requests = g_slist_append(s->requests, req);
}
} | CWE-119 | null | null |
10,035 | static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
{
RngBackend *s = RNG_BACKEND(obj);
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
Error *local_err = NULL;
if (value == s->opened) {
return;
}
if (!value && s->opened) {
error_setg(errp, QERR_PERMISSION_DENIED);
return;
}
if (k->opened) {
k->opened(s, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
}
s->opened = true;
}
| DoS Overflow Mem. Corr. | 0 | static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
{
RngBackend *s = RNG_BACKEND(obj);
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
Error *local_err = NULL;
if (value == s->opened) {
return;
}
if (!value && s->opened) {
error_setg(errp, QERR_PERMISSION_DENIED);
return;
}
if (k->opened) {
k->opened(s, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
}
s->opened = true;
}
| @@ -20,9 +20,20 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,
void *opaque)
{
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
+ RngRequest *req;
if (k->request_entropy) {
- k->request_entropy(s, size, receive_entropy, opaque);
+ req = g_malloc(sizeof(*req));
+
+ req->offset = 0;
+ req->size = size;
+ req->receive_entropy = receive_entropy;
+ req->opaque = opaque;
+ req->data = g_malloc(req->size);
+
+ k->request_entropy(s, req);
+
+ s->requests = g_slist_append(s->requests, req);
}
} | CWE-119 | null | null |
10,036 | uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq)
{
uint32_t sum = 0;
int i;
for (i = seq; i < seq + len; i++) {
if (i & 1) {
sum += (uint32_t)buf[i - seq];
} else {
sum += (uint32_t)buf[i - seq] << 8;
}
}
return sum;
}
| DoS Overflow | 0 | uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq)
{
uint32_t sum = 0;
int i;
for (i = seq; i < seq + len; i++) {
if (i & 1) {
sum += (uint32_t)buf[i - seq];
} else {
sum += (uint32_t)buf[i - seq] << 8;
}
}
return sum;
}
| @@ -60,6 +60,11 @@ void net_checksum_calculate(uint8_t *data, int length)
int hlen, plen, proto, csum_offset;
uint16_t csum;
+ /* Ensure data has complete L2 & L3 headers. */
+ if (length < 14 + 20) {
+ return;
+ }
+
if ((data[14] & 0xf0) != 0x40)
return; /* not IPv4 */
hlen = (data[14] & 0x0f) * 4;
@@ -77,8 +82,9 @@ void net_checksum_calculate(uint8_t *data, int length)
return;
}
- if (plen < csum_offset+2)
- return;
+ if (plen < csum_offset + 2 || 14 + hlen + plen > length) {
+ return;
+ }
data[14+hlen+csum_offset] = 0;
data[14+hlen+csum_offset+1] = 0; | CWE-119 | null | null |
10,037 | uint16_t net_checksum_finish(uint32_t sum)
{
while (sum>>16)
sum = (sum & 0xFFFF)+(sum >> 16);
return ~sum;
}
| DoS Overflow | 0 | uint16_t net_checksum_finish(uint32_t sum)
{
while (sum>>16)
sum = (sum & 0xFFFF)+(sum >> 16);
return ~sum;
}
| @@ -60,6 +60,11 @@ void net_checksum_calculate(uint8_t *data, int length)
int hlen, plen, proto, csum_offset;
uint16_t csum;
+ /* Ensure data has complete L2 & L3 headers. */
+ if (length < 14 + 20) {
+ return;
+ }
+
if ((data[14] & 0xf0) != 0x40)
return; /* not IPv4 */
hlen = (data[14] & 0x0f) * 4;
@@ -77,8 +82,9 @@ void net_checksum_calculate(uint8_t *data, int length)
return;
}
- if (plen < csum_offset+2)
- return;
+ if (plen < csum_offset + 2 || 14 + hlen + plen > length) {
+ return;
+ }
data[14+hlen+csum_offset] = 0;
data[14+hlen+csum_offset+1] = 0; | CWE-119 | null | null |
10,038 | uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
uint8_t *addrs, uint8_t *buf)
{
uint32_t sum = 0;
sum += net_checksum_add(length, buf); // payload
sum += net_checksum_add(8, addrs); // src + dst address
sum += proto + length; // protocol & length
return net_checksum_finish(sum);
}
| DoS Overflow | 0 | uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
uint8_t *addrs, uint8_t *buf)
{
uint32_t sum = 0;
sum += net_checksum_add(length, buf); // payload
sum += net_checksum_add(8, addrs); // src + dst address
sum += proto + length; // protocol & length
return net_checksum_finish(sum);
}
| @@ -60,6 +60,11 @@ void net_checksum_calculate(uint8_t *data, int length)
int hlen, plen, proto, csum_offset;
uint16_t csum;
+ /* Ensure data has complete L2 & L3 headers. */
+ if (length < 14 + 20) {
+ return;
+ }
+
if ((data[14] & 0xf0) != 0x40)
return; /* not IPv4 */
hlen = (data[14] & 0x0f) * 4;
@@ -77,8 +82,9 @@ void net_checksum_calculate(uint8_t *data, int length)
return;
}
- if (plen < csum_offset+2)
- return;
+ if (plen < csum_offset + 2 || 14 + hlen + plen > length) {
+ return;
+ }
data[14+hlen+csum_offset] = 0;
data[14+hlen+csum_offset+1] = 0; | CWE-119 | null | null |
10,039 | static uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int ret;
if (s->dcfg & 0x01) {
/* 16 bit access */
ret = ne2000_mem_readw(s, s->rsar);
ne2000_dma_update(s, 2);
} else {
/* 8 bit access */
ret = ne2000_mem_readb(s, s->rsar);
ne2000_dma_update(s, 1);
}
#ifdef DEBUG_NE2000
printf("NE2000: asic read val=0x%04x\n", ret);
#endif
return ret;
}
| DoS | 0 | static uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int ret;
if (s->dcfg & 0x01) {
/* 16 bit access */
ret = ne2000_mem_readw(s, s->rsar);
ne2000_dma_update(s, 2);
} else {
/* 8 bit access */
ret = ne2000_mem_readb(s, s->rsar);
ne2000_dma_update(s, 1);
}
#ifdef DEBUG_NE2000
printf("NE2000: asic read val=0x%04x\n", ret);
#endif
return ret;
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,040 | static uint32_t ne2000_asic_ioport_readl(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int ret;
/* 32 bit access */
ret = ne2000_mem_readl(s, s->rsar);
ne2000_dma_update(s, 4);
#ifdef DEBUG_NE2000
printf("NE2000: asic readl val=0x%04x\n", ret);
#endif
return ret;
}
| DoS | 0 | static uint32_t ne2000_asic_ioport_readl(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int ret;
/* 32 bit access */
ret = ne2000_mem_readl(s, s->rsar);
ne2000_dma_update(s, 4);
#ifdef DEBUG_NE2000
printf("NE2000: asic readl val=0x%04x\n", ret);
#endif
return ret;
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,041 | static void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
#ifdef DEBUG_NE2000
printf("NE2000: asic write val=0x%04x\n", val);
#endif
if (s->rcnt == 0)
return;
if (s->dcfg & 0x01) {
/* 16 bit access */
ne2000_mem_writew(s, s->rsar, val);
ne2000_dma_update(s, 2);
} else {
/* 8 bit access */
ne2000_mem_writeb(s, s->rsar, val);
ne2000_dma_update(s, 1);
}
}
| DoS | 0 | static void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
#ifdef DEBUG_NE2000
printf("NE2000: asic write val=0x%04x\n", val);
#endif
if (s->rcnt == 0)
return;
if (s->dcfg & 0x01) {
/* 16 bit access */
ne2000_mem_writew(s, s->rsar, val);
ne2000_dma_update(s, 2);
} else {
/* 8 bit access */
ne2000_mem_writeb(s, s->rsar, val);
ne2000_dma_update(s, 1);
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,042 | static void ne2000_asic_ioport_writel(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
#ifdef DEBUG_NE2000
printf("NE2000: asic writel val=0x%04x\n", val);
#endif
if (s->rcnt == 0)
return;
/* 32 bit access */
ne2000_mem_writel(s, s->rsar, val);
ne2000_dma_update(s, 4);
}
| DoS | 0 | static void ne2000_asic_ioport_writel(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
#ifdef DEBUG_NE2000
printf("NE2000: asic writel val=0x%04x\n", val);
#endif
if (s->rcnt == 0)
return;
/* 32 bit access */
ne2000_mem_writel(s, s->rsar, val);
ne2000_dma_update(s, 4);
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,043 | static void ne2000_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
k->realize = pci_ne2000_realize;
k->exit = pci_ne2000_exit;
k->romfile = "efi-ne2k_pci.rom",
k->vendor_id = PCI_VENDOR_ID_REALTEK;
k->device_id = PCI_DEVICE_ID_REALTEK_8029;
k->class_id = PCI_CLASS_NETWORK_ETHERNET;
dc->vmsd = &vmstate_pci_ne2000;
dc->props = ne2000_properties;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
}
| DoS | 0 | static void ne2000_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
k->realize = pci_ne2000_realize;
k->exit = pci_ne2000_exit;
k->romfile = "efi-ne2k_pci.rom",
k->vendor_id = PCI_VENDOR_ID_REALTEK;
k->device_id = PCI_DEVICE_ID_REALTEK_8029;
k->class_id = PCI_CLASS_NETWORK_ETHERNET;
dc->vmsd = &vmstate_pci_ne2000;
dc->props = ne2000_properties;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,044 | static inline void ne2000_dma_update(NE2000State *s, int len)
{
s->rsar += len;
/* wrap */
/* XXX: check what to do if rsar > stop */
if (s->rsar == s->stop)
s->rsar = s->start;
if (s->rcnt <= len) {
s->rcnt = 0;
/* signal end of transfer */
s->isr |= ENISR_RDC;
ne2000_update_irq(s);
} else {
s->rcnt -= len;
}
}
| DoS | 0 | static inline void ne2000_dma_update(NE2000State *s, int len)
{
s->rsar += len;
/* wrap */
/* XXX: check what to do if rsar > stop */
if (s->rsar == s->stop)
s->rsar = s->start;
if (s->rcnt <= len) {
s->rcnt = 0;
/* signal end of transfer */
s->isr |= ENISR_RDC;
ne2000_update_irq(s);
} else {
s->rcnt -= len;
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,045 | static void ne2000_instance_init(Object *obj)
{
PCIDevice *pci_dev = PCI_DEVICE(obj);
PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
NE2000State *s = &d->ne2000;
device_add_bootindex_property(obj, &s->c.bootindex,
"bootindex", "/ethernet-phy@0",
&pci_dev->qdev, NULL);
}
| DoS | 0 | static void ne2000_instance_init(Object *obj)
{
PCIDevice *pci_dev = PCI_DEVICE(obj);
PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
NE2000State *s = &d->ne2000;
device_add_bootindex_property(obj, &s->c.bootindex,
"bootindex", "/ethernet-phy@0",
&pci_dev->qdev, NULL);
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,046 | static uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int offset, page, ret;
addr &= 0xf;
if (addr == E8390_CMD) {
ret = s->cmd;
} else {
page = s->cmd >> 6;
offset = addr | (page << 4);
switch(offset) {
case EN0_TSR:
ret = s->tsr;
break;
case EN0_BOUNDARY:
ret = s->boundary;
break;
case EN0_ISR:
ret = s->isr;
break;
case EN0_RSARLO:
ret = s->rsar & 0x00ff;
break;
case EN0_RSARHI:
ret = s->rsar >> 8;
break;
case EN1_PHYS ... EN1_PHYS + 5:
ret = s->phys[offset - EN1_PHYS];
break;
case EN1_CURPAG:
ret = s->curpag;
break;
case EN1_MULT ... EN1_MULT + 7:
ret = s->mult[offset - EN1_MULT];
break;
case EN0_RSR:
ret = s->rsr;
break;
case EN2_STARTPG:
ret = s->start >> 8;
break;
case EN2_STOPPG:
ret = s->stop >> 8;
break;
case EN0_RTL8029ID0:
ret = 0x50;
break;
case EN0_RTL8029ID1:
ret = 0x43;
break;
case EN3_CONFIG0:
ret = 0; /* 10baseT media */
break;
case EN3_CONFIG2:
ret = 0x40; /* 10baseT active */
break;
case EN3_CONFIG3:
ret = 0x40; /* Full duplex */
break;
default:
ret = 0x00;
break;
}
}
#ifdef DEBUG_NE2000
printf("NE2000: read addr=0x%x val=%02x\n", addr, ret);
#endif
return ret;
}
| DoS | 0 | static uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
int offset, page, ret;
addr &= 0xf;
if (addr == E8390_CMD) {
ret = s->cmd;
} else {
page = s->cmd >> 6;
offset = addr | (page << 4);
switch(offset) {
case EN0_TSR:
ret = s->tsr;
break;
case EN0_BOUNDARY:
ret = s->boundary;
break;
case EN0_ISR:
ret = s->isr;
break;
case EN0_RSARLO:
ret = s->rsar & 0x00ff;
break;
case EN0_RSARHI:
ret = s->rsar >> 8;
break;
case EN1_PHYS ... EN1_PHYS + 5:
ret = s->phys[offset - EN1_PHYS];
break;
case EN1_CURPAG:
ret = s->curpag;
break;
case EN1_MULT ... EN1_MULT + 7:
ret = s->mult[offset - EN1_MULT];
break;
case EN0_RSR:
ret = s->rsr;
break;
case EN2_STARTPG:
ret = s->start >> 8;
break;
case EN2_STOPPG:
ret = s->stop >> 8;
break;
case EN0_RTL8029ID0:
ret = 0x50;
break;
case EN0_RTL8029ID1:
ret = 0x43;
break;
case EN3_CONFIG0:
ret = 0; /* 10baseT media */
break;
case EN3_CONFIG2:
ret = 0x40; /* 10baseT active */
break;
case EN3_CONFIG3:
ret = 0x40; /* Full duplex */
break;
default:
ret = 0x00;
break;
}
}
#ifdef DEBUG_NE2000
printf("NE2000: read addr=0x%x val=%02x\n", addr, ret);
#endif
return ret;
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,047 | static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
int offset, page, index;
addr &= 0xf;
#ifdef DEBUG_NE2000
printf("NE2000: write addr=0x%x val=0x%02x\n", addr, val);
#endif
if (addr == E8390_CMD) {
/* control register */
s->cmd = val;
if (!(val & E8390_STOP)) { /* START bit makes no sense on RTL8029... */
s->isr &= ~ENISR_RESET;
/* test specific case: zero length transfer */
if ((val & (E8390_RREAD | E8390_RWRITE)) &&
s->rcnt == 0) {
s->isr |= ENISR_RDC;
ne2000_update_irq(s);
}
if (val & E8390_TRANS) {
index = (s->tpsr << 8);
/* XXX: next 2 lines are a hack to make netware 3.11 work */
if (index >= NE2000_PMEM_END)
index -= NE2000_PMEM_SIZE;
/* fail safe: check range on the transmitted length */
if (index + s->tcnt <= NE2000_PMEM_END) {
qemu_send_packet(qemu_get_queue(s->nic), s->mem + index,
s->tcnt);
}
/* signal end of transfer */
s->tsr = ENTSR_PTX;
s->isr |= ENISR_TX;
s->cmd &= ~E8390_TRANS;
ne2000_update_irq(s);
}
}
} else {
page = s->cmd >> 6;
offset = addr | (page << 4);
switch(offset) {
case EN0_STARTPG:
if (val << 8 <= NE2000_PMEM_END) {
s->start = val << 8;
}
break;
case EN0_STOPPG:
if (val << 8 <= NE2000_PMEM_END) {
s->stop = val << 8;
}
break;
case EN0_BOUNDARY:
if (val << 8 < NE2000_PMEM_END) {
s->boundary = val;
}
break;
case EN0_IMR:
s->imr = val;
ne2000_update_irq(s);
break;
case EN0_TPSR:
s->tpsr = val;
break;
case EN0_TCNTLO:
s->tcnt = (s->tcnt & 0xff00) | val;
break;
case EN0_TCNTHI:
s->tcnt = (s->tcnt & 0x00ff) | (val << 8);
break;
case EN0_RSARLO:
s->rsar = (s->rsar & 0xff00) | val;
break;
case EN0_RSARHI:
s->rsar = (s->rsar & 0x00ff) | (val << 8);
break;
case EN0_RCNTLO:
s->rcnt = (s->rcnt & 0xff00) | val;
break;
case EN0_RCNTHI:
s->rcnt = (s->rcnt & 0x00ff) | (val << 8);
break;
case EN0_RXCR:
s->rxcr = val;
break;
case EN0_DCFG:
s->dcfg = val;
break;
case EN0_ISR:
s->isr &= ~(val & 0x7f);
ne2000_update_irq(s);
break;
case EN1_PHYS ... EN1_PHYS + 5:
s->phys[offset - EN1_PHYS] = val;
break;
case EN1_CURPAG:
if (val << 8 < NE2000_PMEM_END) {
s->curpag = val;
}
break;
case EN1_MULT ... EN1_MULT + 7:
s->mult[offset - EN1_MULT] = val;
break;
}
}
}
| DoS | 0 | static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
NE2000State *s = opaque;
int offset, page, index;
addr &= 0xf;
#ifdef DEBUG_NE2000
printf("NE2000: write addr=0x%x val=0x%02x\n", addr, val);
#endif
if (addr == E8390_CMD) {
/* control register */
s->cmd = val;
if (!(val & E8390_STOP)) { /* START bit makes no sense on RTL8029... */
s->isr &= ~ENISR_RESET;
/* test specific case: zero length transfer */
if ((val & (E8390_RREAD | E8390_RWRITE)) &&
s->rcnt == 0) {
s->isr |= ENISR_RDC;
ne2000_update_irq(s);
}
if (val & E8390_TRANS) {
index = (s->tpsr << 8);
/* XXX: next 2 lines are a hack to make netware 3.11 work */
if (index >= NE2000_PMEM_END)
index -= NE2000_PMEM_SIZE;
/* fail safe: check range on the transmitted length */
if (index + s->tcnt <= NE2000_PMEM_END) {
qemu_send_packet(qemu_get_queue(s->nic), s->mem + index,
s->tcnt);
}
/* signal end of transfer */
s->tsr = ENTSR_PTX;
s->isr |= ENISR_TX;
s->cmd &= ~E8390_TRANS;
ne2000_update_irq(s);
}
}
} else {
page = s->cmd >> 6;
offset = addr | (page << 4);
switch(offset) {
case EN0_STARTPG:
if (val << 8 <= NE2000_PMEM_END) {
s->start = val << 8;
}
break;
case EN0_STOPPG:
if (val << 8 <= NE2000_PMEM_END) {
s->stop = val << 8;
}
break;
case EN0_BOUNDARY:
if (val << 8 < NE2000_PMEM_END) {
s->boundary = val;
}
break;
case EN0_IMR:
s->imr = val;
ne2000_update_irq(s);
break;
case EN0_TPSR:
s->tpsr = val;
break;
case EN0_TCNTLO:
s->tcnt = (s->tcnt & 0xff00) | val;
break;
case EN0_TCNTHI:
s->tcnt = (s->tcnt & 0x00ff) | (val << 8);
break;
case EN0_RSARLO:
s->rsar = (s->rsar & 0xff00) | val;
break;
case EN0_RSARHI:
s->rsar = (s->rsar & 0x00ff) | (val << 8);
break;
case EN0_RCNTLO:
s->rcnt = (s->rcnt & 0xff00) | val;
break;
case EN0_RCNTHI:
s->rcnt = (s->rcnt & 0x00ff) | (val << 8);
break;
case EN0_RXCR:
s->rxcr = val;
break;
case EN0_DCFG:
s->dcfg = val;
break;
case EN0_ISR:
s->isr &= ~(val & 0x7f);
ne2000_update_irq(s);
break;
case EN1_PHYS ... EN1_PHYS + 5:
s->phys[offset - EN1_PHYS] = val;
break;
case EN1_CURPAG:
if (val << 8 < NE2000_PMEM_END) {
s->curpag = val;
}
break;
case EN1_MULT ... EN1_MULT + 7:
s->mult[offset - EN1_MULT] = val;
break;
}
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,048 | static inline uint32_t ne2000_mem_readb(NE2000State *s, uint32_t addr)
{
if (addr < 32 ||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
return s->mem[addr];
} else {
return 0xff;
}
}
| DoS | 0 | static inline uint32_t ne2000_mem_readb(NE2000State *s, uint32_t addr)
{
if (addr < 32 ||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
return s->mem[addr];
} else {
return 0xff;
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,049 | static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32
|| (addr >= NE2000_PMEM_START
&& addr + sizeof(uint32_t) <= NE2000_MEM_SIZE)) {
return ldl_le_p(s->mem + addr);
} else {
return 0xffffffff;
}
}
| DoS | 0 | static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32
|| (addr >= NE2000_PMEM_START
&& addr + sizeof(uint32_t) <= NE2000_MEM_SIZE)) {
return ldl_le_p(s->mem + addr);
} else {
return 0xffffffff;
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,050 | static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32 ||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
return le16_to_cpu(*(uint16_t *)(s->mem + addr));
} else {
return 0xffff;
}
}
| DoS | 0 | static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32 ||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
return le16_to_cpu(*(uint16_t *)(s->mem + addr));
} else {
return 0xffff;
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,051 | static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
uint32_t val)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32
|| (addr >= NE2000_PMEM_START
&& addr + sizeof(uint32_t) <= NE2000_MEM_SIZE)) {
stl_le_p(s->mem + addr, val);
}
}
| DoS | 0 | static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
uint32_t val)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32
|| (addr >= NE2000_PMEM_START
&& addr + sizeof(uint32_t) <= NE2000_MEM_SIZE)) {
stl_le_p(s->mem + addr, val);
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,052 | static inline void ne2000_mem_writew(NE2000State *s, uint32_t addr,
uint32_t val)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32 ||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
*(uint16_t *)(s->mem + addr) = cpu_to_le16(val);
}
}
| DoS | 0 | static inline void ne2000_mem_writew(NE2000State *s, uint32_t addr,
uint32_t val)
{
addr &= ~1; /* XXX: check exact behaviour if not even */
if (addr < 32 ||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
*(uint16_t *)(s->mem + addr) = cpu_to_le16(val);
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,053 | static int ne2000_post_load(void* opaque, int version_id)
{
NE2000State* s = opaque;
if (version_id < 2) {
s->rxcr = 0x0c;
}
return 0;
}
| DoS | 0 | static int ne2000_post_load(void* opaque, int version_id)
{
NE2000State* s = opaque;
if (version_id < 2) {
s->rxcr = 0x0c;
}
return 0;
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,054 | ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
{
NE2000State *s = qemu_get_nic_opaque(nc);
int size = size_;
uint8_t *p;
unsigned int total_len, next, avail, len, index, mcast_idx;
uint8_t buf1[60];
static const uint8_t broadcast_macaddr[6] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
#if defined(DEBUG_NE2000)
printf("NE2000: received len=%d\n", size);
#endif
if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
return -1;
/* XXX: check this */
if (s->rxcr & 0x10) {
/* promiscuous: receive all */
} else {
if (!memcmp(buf, broadcast_macaddr, 6)) {
/* broadcast address */
if (!(s->rxcr & 0x04))
return size;
} else if (buf[0] & 0x01) {
/* multicast */
if (!(s->rxcr & 0x08))
return size;
mcast_idx = compute_mcast_idx(buf);
if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
return size;
} else if (s->mem[0] == buf[0] &&
s->mem[2] == buf[1] &&
s->mem[4] == buf[2] &&
s->mem[6] == buf[3] &&
s->mem[8] == buf[4] &&
s->mem[10] == buf[5]) {
/* match */
} else {
return size;
}
}
/* if too small buffer, then expand it */
if (size < MIN_BUF_SIZE) {
memcpy(buf1, buf, size);
memset(buf1 + size, 0, MIN_BUF_SIZE - size);
buf = buf1;
size = MIN_BUF_SIZE;
}
index = s->curpag << 8;
if (index >= NE2000_PMEM_END) {
index = s->start;
}
/* 4 bytes for header */
total_len = size + 4;
/* address for next packet (4 bytes for CRC) */
next = index + ((total_len + 4 + 255) & ~0xff);
if (next >= s->stop)
next -= (s->stop - s->start);
/* prepare packet header */
p = s->mem + index;
s->rsr = ENRSR_RXOK; /* receive status */
/* XXX: check this */
if (buf[0] & 0x01)
s->rsr |= ENRSR_PHY;
p[0] = s->rsr;
p[1] = next >> 8;
p[2] = total_len;
p[3] = total_len >> 8;
index += 4;
/* write packet data */
while (size > 0) {
if (index <= s->stop)
avail = s->stop - index;
else
break;
len = size;
if (len > avail)
len = avail;
memcpy(s->mem + index, buf, len);
buf += len;
index += len;
if (index == s->stop)
index = s->start;
size -= len;
}
s->curpag = next >> 8;
/* now we can signal we have received something */
s->isr |= ENISR_RX;
ne2000_update_irq(s);
return size_;
}
| DoS | 0 | ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
{
NE2000State *s = qemu_get_nic_opaque(nc);
int size = size_;
uint8_t *p;
unsigned int total_len, next, avail, len, index, mcast_idx;
uint8_t buf1[60];
static const uint8_t broadcast_macaddr[6] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
#if defined(DEBUG_NE2000)
printf("NE2000: received len=%d\n", size);
#endif
if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
return -1;
/* XXX: check this */
if (s->rxcr & 0x10) {
/* promiscuous: receive all */
} else {
if (!memcmp(buf, broadcast_macaddr, 6)) {
/* broadcast address */
if (!(s->rxcr & 0x04))
return size;
} else if (buf[0] & 0x01) {
/* multicast */
if (!(s->rxcr & 0x08))
return size;
mcast_idx = compute_mcast_idx(buf);
if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
return size;
} else if (s->mem[0] == buf[0] &&
s->mem[2] == buf[1] &&
s->mem[4] == buf[2] &&
s->mem[6] == buf[3] &&
s->mem[8] == buf[4] &&
s->mem[10] == buf[5]) {
/* match */
} else {
return size;
}
}
/* if too small buffer, then expand it */
if (size < MIN_BUF_SIZE) {
memcpy(buf1, buf, size);
memset(buf1 + size, 0, MIN_BUF_SIZE - size);
buf = buf1;
size = MIN_BUF_SIZE;
}
index = s->curpag << 8;
if (index >= NE2000_PMEM_END) {
index = s->start;
}
/* 4 bytes for header */
total_len = size + 4;
/* address for next packet (4 bytes for CRC) */
next = index + ((total_len + 4 + 255) & ~0xff);
if (next >= s->stop)
next -= (s->stop - s->start);
/* prepare packet header */
p = s->mem + index;
s->rsr = ENRSR_RXOK; /* receive status */
/* XXX: check this */
if (buf[0] & 0x01)
s->rsr |= ENRSR_PHY;
p[0] = s->rsr;
p[1] = next >> 8;
p[2] = total_len;
p[3] = total_len >> 8;
index += 4;
/* write packet data */
while (size > 0) {
if (index <= s->stop)
avail = s->stop - index;
else
break;
len = size;
if (len > avail)
len = avail;
memcpy(s->mem + index, buf, len);
buf += len;
index += len;
if (index == s->stop)
index = s->start;
size -= len;
}
s->curpag = next >> 8;
/* now we can signal we have received something */
s->isr |= ENISR_RX;
ne2000_update_irq(s);
return size_;
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,055 | static void ne2000_register_types(void)
{
type_register_static(&ne2000_info);
}
| DoS | 0 | static void ne2000_register_types(void)
{
type_register_static(&ne2000_info);
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,056 | void ne2000_reset(NE2000State *s)
{
int i;
s->isr = ENISR_RESET;
memcpy(s->mem, &s->c.macaddr, 6);
s->mem[14] = 0x57;
s->mem[15] = 0x57;
/* duplicate prom data */
for(i = 15;i >= 0; i--) {
s->mem[2 * i] = s->mem[i];
s->mem[2 * i + 1] = s->mem[i];
}
}
| DoS | 0 | void ne2000_reset(NE2000State *s)
{
int i;
s->isr = ENISR_RESET;
memcpy(s->mem, &s->c.macaddr, 6);
s->mem[14] = 0x57;
s->mem[15] = 0x57;
/* duplicate prom data */
for(i = 15;i >= 0; i--) {
s->mem[2 * i] = s->mem[i];
s->mem[2 * i + 1] = s->mem[i];
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,057 | static uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
ne2000_reset(s);
return 0;
}
| DoS | 0 | static uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
{
NE2000State *s = opaque;
ne2000_reset(s);
return 0;
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,058 | void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size)
{
memory_region_init_io(&s->io, OBJECT(dev), &ne2000_ops, s, "ne2000", size);
}
| DoS | 0 | void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size)
{
memory_region_init_io(&s->io, OBJECT(dev), &ne2000_ops, s, "ne2000", size);
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,059 | static void ne2000_update_irq(NE2000State *s)
{
int isr;
isr = (s->isr & s->imr) & 0x7f;
#if defined(DEBUG_NE2000)
printf("NE2000: Set IRQ to %d (%02x %02x)\n",
isr ? 1 : 0, s->isr, s->imr);
#endif
qemu_set_irq(s->irq, (isr != 0));
}
| DoS | 0 | static void ne2000_update_irq(NE2000State *s)
{
int isr;
isr = (s->isr & s->imr) & 0x7f;
#if defined(DEBUG_NE2000)
printf("NE2000: Set IRQ to %d (%02x %02x)\n",
isr ? 1 : 0, s->isr, s->imr);
#endif
qemu_set_irq(s->irq, (isr != 0));
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,060 | static void ne2000_write(void *opaque, hwaddr addr,
uint64_t data, unsigned size)
{
NE2000State *s = opaque;
if (addr < 0x10 && size == 1) {
ne2000_ioport_write(s, addr, data);
} else if (addr == 0x10) {
if (size <= 2) {
ne2000_asic_ioport_write(s, addr, data);
} else {
ne2000_asic_ioport_writel(s, addr, data);
}
} else if (addr == 0x1f && size == 1) {
ne2000_reset_ioport_write(s, addr, data);
}
}
| DoS | 0 | static void ne2000_write(void *opaque, hwaddr addr,
uint64_t data, unsigned size)
{
NE2000State *s = opaque;
if (addr < 0x10 && size == 1) {
ne2000_ioport_write(s, addr, data);
} else if (addr == 0x10) {
if (size <= 2) {
ne2000_asic_ioport_write(s, addr, data);
} else {
ne2000_asic_ioport_writel(s, addr, data);
}
} else if (addr == 0x1f && size == 1) {
ne2000_reset_ioport_write(s, addr, data);
}
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,061 | static void pci_ne2000_realize(PCIDevice *pci_dev, Error **errp)
{
PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
NE2000State *s;
uint8_t *pci_conf;
pci_conf = d->dev.config;
pci_conf[PCI_INTERRUPT_PIN] = 1; /* interrupt pin A */
s = &d->ne2000;
ne2000_setup_io(s, DEVICE(pci_dev), 0x100);
pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
s->irq = pci_allocate_irq(&d->dev);
qemu_macaddr_default_if_unset(&s->c.macaddr);
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
}
| DoS | 0 | static void pci_ne2000_realize(PCIDevice *pci_dev, Error **errp)
{
PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
NE2000State *s;
uint8_t *pci_conf;
pci_conf = d->dev.config;
pci_conf[PCI_INTERRUPT_PIN] = 1; /* interrupt pin A */
s = &d->ne2000;
ne2000_setup_io(s, DEVICE(pci_dev), 0x100);
pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
s->irq = pci_allocate_irq(&d->dev);
qemu_macaddr_default_if_unset(&s->c.macaddr);
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
}
| @@ -155,6 +155,10 @@ static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
+ if (s->stop <= s->start) {
+ return 1;
+ }
+
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary) | CWE-20 | null | null |
10,062 | static int is_rndis(USBNetState *s)
{
return s->dev.config ?
s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
| DoS Overflow +Info | 0 | static int is_rndis(USBNetState *s)
{
return s->dev.config ?
s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,063 | static int ndis_set(USBNetState *s, uint32_t oid,
uint8_t *inbuf, unsigned int inlen)
{
switch (oid) {
case OID_GEN_CURRENT_PACKET_FILTER:
s->filter = le32_to_cpup((le32 *) inbuf);
if (s->filter) {
s->rndis_state = RNDIS_DATA_INITIALIZED;
} else {
s->rndis_state = RNDIS_INITIALIZED;
}
return 0;
case OID_802_3_MULTICAST_LIST:
return 0;
}
return -1;
}
| DoS Overflow +Info | 0 | static int ndis_set(USBNetState *s, uint32_t oid,
uint8_t *inbuf, unsigned int inlen)
{
switch (oid) {
case OID_GEN_CURRENT_PACKET_FILTER:
s->filter = le32_to_cpup((le32 *) inbuf);
if (s->filter) {
s->rndis_state = RNDIS_DATA_INITIALIZED;
} else {
s->rndis_state = RNDIS_INITIALIZED;
}
return 0;
case OID_802_3_MULTICAST_LIST:
return 0;
}
return -1;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,064 | static void rndis_clear_responsequeue(USBNetState *s)
{
struct rndis_response *r;
while ((r = s->rndis_resp.tqh_first)) {
QTAILQ_REMOVE(&s->rndis_resp, r, entries);
g_free(r);
}
}
| DoS Overflow +Info | 0 | static void rndis_clear_responsequeue(USBNetState *s)
{
struct rndis_response *r;
while ((r = s->rndis_resp.tqh_first)) {
QTAILQ_REMOVE(&s->rndis_resp, r, entries);
g_free(r);
}
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,065 | static int rndis_get_response(USBNetState *s, uint8_t *buf)
{
int ret = 0;
struct rndis_response *r = s->rndis_resp.tqh_first;
if (!r)
return ret;
QTAILQ_REMOVE(&s->rndis_resp, r, entries);
ret = r->length;
memcpy(buf, r->buf, r->length);
g_free(r);
return ret;
}
| DoS Overflow +Info | 0 | static int rndis_get_response(USBNetState *s, uint8_t *buf)
{
int ret = 0;
struct rndis_response *r = s->rndis_resp.tqh_first;
if (!r)
return ret;
QTAILQ_REMOVE(&s->rndis_resp, r, entries);
ret = r->length;
memcpy(buf, r->buf, r->length);
g_free(r);
return ret;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,066 | static int rndis_init_response(USBNetState *s, rndis_init_msg_type *buf)
{
rndis_init_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_init_cmplt_type));
if (!resp)
return USB_RET_STALL;
resp->MessageType = cpu_to_le32(RNDIS_INITIALIZE_CMPLT);
resp->MessageLength = cpu_to_le32(sizeof(rndis_init_cmplt_type));
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
resp->MaxPacketsPerTransfer = cpu_to_le32(1);
resp->MaxTransferSize = cpu_to_le32(ETH_FRAME_LEN +
sizeof(struct rndis_packet_msg_type) + 22);
resp->PacketAlignmentFactor = cpu_to_le32(0);
resp->AFListOffset = cpu_to_le32(0);
resp->AFListSize = cpu_to_le32(0);
return 0;
}
| DoS Overflow +Info | 0 | static int rndis_init_response(USBNetState *s, rndis_init_msg_type *buf)
{
rndis_init_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_init_cmplt_type));
if (!resp)
return USB_RET_STALL;
resp->MessageType = cpu_to_le32(RNDIS_INITIALIZE_CMPLT);
resp->MessageLength = cpu_to_le32(sizeof(rndis_init_cmplt_type));
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
resp->MaxPacketsPerTransfer = cpu_to_le32(1);
resp->MaxTransferSize = cpu_to_le32(ETH_FRAME_LEN +
sizeof(struct rndis_packet_msg_type) + 22);
resp->PacketAlignmentFactor = cpu_to_le32(0);
resp->AFListOffset = cpu_to_le32(0);
resp->AFListSize = cpu_to_le32(0);
return 0;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,067 | static int rndis_keepalive_response(USBNetState *s,
rndis_keepalive_msg_type *buf)
{
rndis_keepalive_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_keepalive_cmplt_type));
if (!resp)
return USB_RET_STALL;
resp->MessageType = cpu_to_le32(RNDIS_KEEPALIVE_CMPLT);
resp->MessageLength = cpu_to_le32(sizeof(rndis_keepalive_cmplt_type));
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
return 0;
}
| DoS Overflow +Info | 0 | static int rndis_keepalive_response(USBNetState *s,
rndis_keepalive_msg_type *buf)
{
rndis_keepalive_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_keepalive_cmplt_type));
if (!resp)
return USB_RET_STALL;
resp->MessageType = cpu_to_le32(RNDIS_KEEPALIVE_CMPLT);
resp->MessageLength = cpu_to_le32(sizeof(rndis_keepalive_cmplt_type));
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
return 0;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,068 | static int rndis_parse(USBNetState *s, uint8_t *data, int length)
{
uint32_t msg_type;
le32 *tmp = (le32 *) data;
msg_type = le32_to_cpup(tmp);
switch (msg_type) {
case RNDIS_INITIALIZE_MSG:
s->rndis_state = RNDIS_INITIALIZED;
return rndis_init_response(s, (rndis_init_msg_type *) data);
case RNDIS_HALT_MSG:
s->rndis_state = RNDIS_UNINITIALIZED;
return 0;
case RNDIS_QUERY_MSG:
return rndis_query_response(s, (rndis_query_msg_type *) data, length);
case RNDIS_SET_MSG:
return rndis_set_response(s, (rndis_set_msg_type *) data, length);
case RNDIS_RESET_MSG:
rndis_clear_responsequeue(s);
s->out_ptr = 0;
usb_net_reset_in_buf(s);
return rndis_reset_response(s, (rndis_reset_msg_type *) data);
case RNDIS_KEEPALIVE_MSG:
/* For USB: host does this every 5 seconds */
return rndis_keepalive_response(s, (rndis_keepalive_msg_type *) data);
}
return USB_RET_STALL;
}
| DoS Overflow +Info | 0 | static int rndis_parse(USBNetState *s, uint8_t *data, int length)
{
uint32_t msg_type;
le32 *tmp = (le32 *) data;
msg_type = le32_to_cpup(tmp);
switch (msg_type) {
case RNDIS_INITIALIZE_MSG:
s->rndis_state = RNDIS_INITIALIZED;
return rndis_init_response(s, (rndis_init_msg_type *) data);
case RNDIS_HALT_MSG:
s->rndis_state = RNDIS_UNINITIALIZED;
return 0;
case RNDIS_QUERY_MSG:
return rndis_query_response(s, (rndis_query_msg_type *) data, length);
case RNDIS_SET_MSG:
return rndis_set_response(s, (rndis_set_msg_type *) data, length);
case RNDIS_RESET_MSG:
rndis_clear_responsequeue(s);
s->out_ptr = 0;
usb_net_reset_in_buf(s);
return rndis_reset_response(s, (rndis_reset_msg_type *) data);
case RNDIS_KEEPALIVE_MSG:
/* For USB: host does this every 5 seconds */
return rndis_keepalive_response(s, (rndis_keepalive_msg_type *) data);
}
return USB_RET_STALL;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,069 | static void *rndis_queue_response(USBNetState *s, unsigned int length)
{
struct rndis_response *r =
g_malloc0(sizeof(struct rndis_response) + length);
if (QTAILQ_EMPTY(&s->rndis_resp)) {
usb_wakeup(s->intr, 0);
}
QTAILQ_INSERT_TAIL(&s->rndis_resp, r, entries);
r->length = length;
return &r->buf[0];
}
| DoS Overflow +Info | 0 | static void *rndis_queue_response(USBNetState *s, unsigned int length)
{
struct rndis_response *r =
g_malloc0(sizeof(struct rndis_response) + length);
if (QTAILQ_EMPTY(&s->rndis_resp)) {
usb_wakeup(s->intr, 0);
}
QTAILQ_INSERT_TAIL(&s->rndis_resp, r, entries);
r->length = length;
return &r->buf[0];
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,070 | static int rndis_reset_response(USBNetState *s, rndis_reset_msg_type *buf)
{
rndis_reset_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_reset_cmplt_type));
if (!resp)
return USB_RET_STALL;
resp->MessageType = cpu_to_le32(RNDIS_RESET_CMPLT);
resp->MessageLength = cpu_to_le32(sizeof(rndis_reset_cmplt_type));
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
resp->AddressingReset = cpu_to_le32(1); /* reset information */
return 0;
}
| DoS Overflow +Info | 0 | static int rndis_reset_response(USBNetState *s, rndis_reset_msg_type *buf)
{
rndis_reset_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_reset_cmplt_type));
if (!resp)
return USB_RET_STALL;
resp->MessageType = cpu_to_le32(RNDIS_RESET_CMPLT);
resp->MessageLength = cpu_to_le32(sizeof(rndis_reset_cmplt_type));
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
resp->AddressingReset = cpu_to_le32(1); /* reset information */
return 0;
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,071 | static void usb_net_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
USBNetState *s = (USBNetState *) dev;
int ret;
ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
if (ret >= 0) {
return;
}
switch(request) {
case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND:
if (!is_rndis(s) || value || index != 0) {
goto fail;
}
#ifdef TRAFFIC_DEBUG
{
unsigned int i;
fprintf(stderr, "SEND_ENCAPSULATED_COMMAND:");
for (i = 0; i < length; i++) {
if (!(i & 15))
fprintf(stderr, "\n%04x:", i);
fprintf(stderr, " %02x", data[i]);
}
fprintf(stderr, "\n\n");
}
#endif
ret = rndis_parse(s, data, length);
if (ret < 0) {
p->status = ret;
}
break;
case ClassInterfaceRequest | USB_CDC_GET_ENCAPSULATED_RESPONSE:
if (!is_rndis(s) || value || index != 0) {
goto fail;
}
p->actual_length = rndis_get_response(s, data);
if (p->actual_length == 0) {
data[0] = 0;
p->actual_length = 1;
}
#ifdef TRAFFIC_DEBUG
{
unsigned int i;
fprintf(stderr, "GET_ENCAPSULATED_RESPONSE:");
for (i = 0; i < p->actual_length; i++) {
if (!(i & 15))
fprintf(stderr, "\n%04x:", i);
fprintf(stderr, " %02x", data[i]);
}
fprintf(stderr, "\n\n");
}
#endif
break;
default:
fail:
fprintf(stderr, "usbnet: failed control transaction: "
"request 0x%x value 0x%x index 0x%x length 0x%x\n",
request, value, index, length);
p->status = USB_RET_STALL;
break;
}
}
| DoS Overflow +Info | 0 | static void usb_net_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
USBNetState *s = (USBNetState *) dev;
int ret;
ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
if (ret >= 0) {
return;
}
switch(request) {
case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND:
if (!is_rndis(s) || value || index != 0) {
goto fail;
}
#ifdef TRAFFIC_DEBUG
{
unsigned int i;
fprintf(stderr, "SEND_ENCAPSULATED_COMMAND:");
for (i = 0; i < length; i++) {
if (!(i & 15))
fprintf(stderr, "\n%04x:", i);
fprintf(stderr, " %02x", data[i]);
}
fprintf(stderr, "\n\n");
}
#endif
ret = rndis_parse(s, data, length);
if (ret < 0) {
p->status = ret;
}
break;
case ClassInterfaceRequest | USB_CDC_GET_ENCAPSULATED_RESPONSE:
if (!is_rndis(s) || value || index != 0) {
goto fail;
}
p->actual_length = rndis_get_response(s, data);
if (p->actual_length == 0) {
data[0] = 0;
p->actual_length = 1;
}
#ifdef TRAFFIC_DEBUG
{
unsigned int i;
fprintf(stderr, "GET_ENCAPSULATED_RESPONSE:");
for (i = 0; i < p->actual_length; i++) {
if (!(i & 15))
fprintf(stderr, "\n%04x:", i);
fprintf(stderr, " %02x", data[i]);
}
fprintf(stderr, "\n\n");
}
#endif
break;
default:
fail:
fprintf(stderr, "usbnet: failed control transaction: "
"request 0x%x value 0x%x index 0x%x length 0x%x\n",
request, value, index, length);
p->status = USB_RET_STALL;
break;
}
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,072 | static void usb_net_handle_datain(USBNetState *s, USBPacket *p)
{
int len;
if (s->in_ptr > s->in_len) {
usb_net_reset_in_buf(s);
p->status = USB_RET_NAK;
return;
}
if (!s->in_len) {
p->status = USB_RET_NAK;
return;
}
len = s->in_len - s->in_ptr;
if (len > p->iov.size) {
len = p->iov.size;
}
usb_packet_copy(p, &s->in_buf[s->in_ptr], len);
s->in_ptr += len;
if (s->in_ptr >= s->in_len &&
(is_rndis(s) || (s->in_len & (64 - 1)) || !len)) {
/* no short packet necessary */
usb_net_reset_in_buf(s);
}
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: data in len %zu return %d", p->iov.size, len);
iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", len);
#endif
}
| DoS Overflow +Info | 0 | static void usb_net_handle_datain(USBNetState *s, USBPacket *p)
{
int len;
if (s->in_ptr > s->in_len) {
usb_net_reset_in_buf(s);
p->status = USB_RET_NAK;
return;
}
if (!s->in_len) {
p->status = USB_RET_NAK;
return;
}
len = s->in_len - s->in_ptr;
if (len > p->iov.size) {
len = p->iov.size;
}
usb_packet_copy(p, &s->in_buf[s->in_ptr], len);
s->in_ptr += len;
if (s->in_ptr >= s->in_len &&
(is_rndis(s) || (s->in_len & (64 - 1)) || !len)) {
/* no short packet necessary */
usb_net_reset_in_buf(s);
}
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: data in len %zu return %d", p->iov.size, len);
iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", len);
#endif
}
| @@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf,
@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
- if (bufoffs + buflen > length)
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL;
+ }
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
- if (offs + size <= len)
+ if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
+ }
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); | CWE-189 | null | null |
10,073 | static int ndis_query(USBNetState *s, uint32_t oid,
size_t outlen)
{
unsigned int i;
switch (oid) {
/* general oids (table 4-1) */
/* mandatory */
case OID_GEN_SUPPORTED_LIST:
for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++)
((le32 *) outbuf)[i] = cpu_to_le32(oid_supported_list[i]);
return sizeof(oid_supported_list);
/* mandatory */
case OID_GEN_HARDWARE_STATUS:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_SUPPORTED:
*((le32 *) outbuf) = cpu_to_le32(s->medium);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_IN_USE:
*((le32 *) outbuf) = cpu_to_le32(s->medium);
return sizeof(le32);
/* mandatory */
case OID_GEN_MAXIMUM_FRAME_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_LINK_SPEED:
*((le32 *) outbuf) = cpu_to_le32(s->speed);
return sizeof(le32);
/* mandatory */
case OID_GEN_TRANSMIT_BLOCK_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_RECEIVE_BLOCK_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_VENDOR_ID:
*((le32 *) outbuf) = cpu_to_le32(s->vendorid);
return sizeof(le32);
/* mandatory */
case OID_GEN_VENDOR_DESCRIPTION:
pstrcpy((char *)outbuf, outlen, "QEMU USB RNDIS Net");
return strlen((char *)outbuf) + 1;
case OID_GEN_VENDOR_DRIVER_VERSION:
*((le32 *) outbuf) = cpu_to_le32(1);
return sizeof(le32);
/* mandatory */
case OID_GEN_CURRENT_PACKET_FILTER:
*((le32 *) outbuf) = cpu_to_le32(s->filter);
return sizeof(le32);
/* mandatory */
case OID_GEN_MAXIMUM_TOTAL_SIZE:
*((le32 *) outbuf) = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_CONNECT_STATUS:
*((le32 *) outbuf) = cpu_to_le32(s->media_state);
return sizeof(le32);
case OID_GEN_PHYSICAL_MEDIUM:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
case OID_GEN_MAC_OPTIONS:
*((le32 *) outbuf) = cpu_to_le32(
NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
NDIS_MAC_OPTION_FULL_DUPLEX);
return sizeof(le32);
/* statistics OIDs (table 4-2) */
/* mandatory */
case OID_GEN_XMIT_OK:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_OK:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_XMIT_ERROR:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_ERROR:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_NO_BUFFER:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* ieee802.3 OIDs (table 4-3) */
/* mandatory */
case OID_802_3_PERMANENT_ADDRESS:
memcpy(outbuf, s->conf.macaddr.a, 6);
return 6;
/* mandatory */
case OID_802_3_CURRENT_ADDRESS:
memcpy(outbuf, s->conf.macaddr.a, 6);
return 6;
/* mandatory */
case OID_802_3_MULTICAST_LIST:
*((le32 *) outbuf) = cpu_to_le32(0xe0000000);
return sizeof(le32);
/* mandatory */
case OID_802_3_MAXIMUM_LIST_SIZE:
*((le32 *) outbuf) = cpu_to_le32(1);
return sizeof(le32);
case OID_802_3_MAC_OPTIONS:
return 0;
/* ieee802.3 statistics OIDs (table 4-4) */
/* mandatory */
case OID_802_3_RCV_ERROR_ALIGNMENT:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_802_3_XMIT_ONE_COLLISION:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_802_3_XMIT_MORE_COLLISIONS:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
default:
fprintf(stderr, "usbnet: unknown OID 0x%08x\n", oid);
return 0;
}
return -1;
}
| DoS | 0 | static int ndis_query(USBNetState *s, uint32_t oid,
size_t outlen)
{
unsigned int i;
switch (oid) {
/* general oids (table 4-1) */
/* mandatory */
case OID_GEN_SUPPORTED_LIST:
for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++)
((le32 *) outbuf)[i] = cpu_to_le32(oid_supported_list[i]);
return sizeof(oid_supported_list);
/* mandatory */
case OID_GEN_HARDWARE_STATUS:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_SUPPORTED:
*((le32 *) outbuf) = cpu_to_le32(s->medium);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_IN_USE:
*((le32 *) outbuf) = cpu_to_le32(s->medium);
return sizeof(le32);
/* mandatory */
case OID_GEN_MAXIMUM_FRAME_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_LINK_SPEED:
*((le32 *) outbuf) = cpu_to_le32(s->speed);
return sizeof(le32);
/* mandatory */
case OID_GEN_TRANSMIT_BLOCK_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_RECEIVE_BLOCK_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_VENDOR_ID:
*((le32 *) outbuf) = cpu_to_le32(s->vendorid);
return sizeof(le32);
/* mandatory */
case OID_GEN_VENDOR_DESCRIPTION:
pstrcpy((char *)outbuf, outlen, "QEMU USB RNDIS Net");
return strlen((char *)outbuf) + 1;
case OID_GEN_VENDOR_DRIVER_VERSION:
*((le32 *) outbuf) = cpu_to_le32(1);
return sizeof(le32);
/* mandatory */
case OID_GEN_CURRENT_PACKET_FILTER:
*((le32 *) outbuf) = cpu_to_le32(s->filter);
return sizeof(le32);
/* mandatory */
case OID_GEN_MAXIMUM_TOTAL_SIZE:
*((le32 *) outbuf) = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_CONNECT_STATUS:
*((le32 *) outbuf) = cpu_to_le32(s->media_state);
return sizeof(le32);
case OID_GEN_PHYSICAL_MEDIUM:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
case OID_GEN_MAC_OPTIONS:
*((le32 *) outbuf) = cpu_to_le32(
NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
NDIS_MAC_OPTION_FULL_DUPLEX);
return sizeof(le32);
/* statistics OIDs (table 4-2) */
/* mandatory */
case OID_GEN_XMIT_OK:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_OK:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_XMIT_ERROR:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_ERROR:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_NO_BUFFER:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* ieee802.3 OIDs (table 4-3) */
/* mandatory */
case OID_802_3_PERMANENT_ADDRESS:
memcpy(outbuf, s->conf.macaddr.a, 6);
return 6;
/* mandatory */
case OID_802_3_CURRENT_ADDRESS:
memcpy(outbuf, s->conf.macaddr.a, 6);
return 6;
/* mandatory */
case OID_802_3_MULTICAST_LIST:
*((le32 *) outbuf) = cpu_to_le32(0xe0000000);
return sizeof(le32);
/* mandatory */
case OID_802_3_MAXIMUM_LIST_SIZE:
*((le32 *) outbuf) = cpu_to_le32(1);
return sizeof(le32);
case OID_802_3_MAC_OPTIONS:
return 0;
/* ieee802.3 statistics OIDs (table 4-4) */
/* mandatory */
case OID_802_3_RCV_ERROR_ALIGNMENT:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_802_3_XMIT_ONE_COLLISION:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
/* mandatory */
case OID_802_3_XMIT_MORE_COLLISIONS:
*((le32 *) outbuf) = cpu_to_le32(0);
return sizeof(le32);
default:
fprintf(stderr, "usbnet: unknown OID 0x%08x\n", oid);
return 0;
}
return -1;
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,074 | static int rndis_set_response(USBNetState *s,
rndis_set_msg_type *buf, unsigned int length)
{
rndis_set_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_set_cmplt_type));
uint32_t bufoffs, buflen;
int ret;
if (!resp)
return USB_RET_STALL;
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
if (bufoffs + buflen > length)
return USB_RET_STALL;
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
resp->MessageType = cpu_to_le32(RNDIS_SET_CMPLT);
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->MessageLength = cpu_to_le32(sizeof(rndis_set_cmplt_type));
if (ret < 0) {
/* OID not supported */
resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
return 0;
}
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
return 0;
}
| DoS | 0 | static int rndis_set_response(USBNetState *s,
rndis_set_msg_type *buf, unsigned int length)
{
rndis_set_cmplt_type *resp =
rndis_queue_response(s, sizeof(rndis_set_cmplt_type));
uint32_t bufoffs, buflen;
int ret;
if (!resp)
return USB_RET_STALL;
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength);
if (bufoffs + buflen > length)
return USB_RET_STALL;
ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen);
resp->MessageType = cpu_to_le32(RNDIS_SET_CMPLT);
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->MessageLength = cpu_to_le32(sizeof(rndis_set_cmplt_type));
if (ret < 0) {
/* OID not supported */
resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
return 0;
}
resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
return 0;
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,075 | static void usb_net_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
uc->realize = usb_net_realize;
uc->product_desc = "QEMU USB Network Interface";
uc->usb_desc = &desc_net;
uc->handle_reset = usb_net_handle_reset;
uc->handle_control = usb_net_handle_control;
uc->handle_data = usb_net_handle_data;
uc->handle_destroy = usb_net_handle_destroy;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
dc->fw_name = "network";
dc->vmsd = &vmstate_usb_net;
dc->props = net_properties;
}
| DoS | 0 | static void usb_net_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
uc->realize = usb_net_realize;
uc->product_desc = "QEMU USB Network Interface";
uc->usb_desc = &desc_net;
uc->handle_reset = usb_net_handle_reset;
uc->handle_control = usb_net_handle_control;
uc->handle_data = usb_net_handle_data;
uc->handle_destroy = usb_net_handle_destroy;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
dc->fw_name = "network";
dc->vmsd = &vmstate_usb_net;
dc->props = net_properties;
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,076 | static void usb_net_handle_data(USBDevice *dev, USBPacket *p)
{
USBNetState *s = (USBNetState *) dev;
switch(p->pid) {
case USB_TOKEN_IN:
switch (p->ep->nr) {
case 1:
usb_net_handle_statusin(s, p);
break;
case 2:
usb_net_handle_datain(s, p);
break;
default:
goto fail;
}
break;
case USB_TOKEN_OUT:
switch (p->ep->nr) {
case 2:
usb_net_handle_dataout(s, p);
break;
default:
goto fail;
}
break;
default:
fail:
p->status = USB_RET_STALL;
break;
}
if (p->status == USB_RET_STALL) {
fprintf(stderr, "usbnet: failed data transaction: "
"pid 0x%x ep 0x%x len 0x%zx\n",
p->pid, p->ep->nr, p->iov.size);
}
}
| DoS | 0 | static void usb_net_handle_data(USBDevice *dev, USBPacket *p)
{
USBNetState *s = (USBNetState *) dev;
switch(p->pid) {
case USB_TOKEN_IN:
switch (p->ep->nr) {
case 1:
usb_net_handle_statusin(s, p);
break;
case 2:
usb_net_handle_datain(s, p);
break;
default:
goto fail;
}
break;
case USB_TOKEN_OUT:
switch (p->ep->nr) {
case 2:
usb_net_handle_dataout(s, p);
break;
default:
goto fail;
}
break;
default:
fail:
p->status = USB_RET_STALL;
break;
}
if (p->status == USB_RET_STALL) {
fprintf(stderr, "usbnet: failed data transaction: "
"pid 0x%x ep 0x%x len 0x%zx\n",
p->pid, p->ep->nr, p->iov.size);
}
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,077 | static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
{
int sz = sizeof(s->out_buf) - s->out_ptr;
struct rndis_packet_msg_type *msg =
(struct rndis_packet_msg_type *) s->out_buf;
uint32_t len;
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: data out len %zu\n", p->iov.size);
iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", p->iov.size);
#endif
if (sz > p->iov.size) {
sz = p->iov.size;
}
usb_packet_copy(p, &s->out_buf[s->out_ptr], sz);
s->out_ptr += sz;
if (!is_rndis(s)) {
if (p->iov.size < 64) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf, s->out_ptr);
s->out_ptr = 0;
}
return;
}
len = le32_to_cpu(msg->MessageLength);
if (s->out_ptr < 8 || s->out_ptr < len) {
return;
}
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
if (offs + size <= len)
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
}
| DoS | 0 | static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
{
int sz = sizeof(s->out_buf) - s->out_ptr;
struct rndis_packet_msg_type *msg =
(struct rndis_packet_msg_type *) s->out_buf;
uint32_t len;
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: data out len %zu\n", p->iov.size);
iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", p->iov.size);
#endif
if (sz > p->iov.size) {
sz = p->iov.size;
}
usb_packet_copy(p, &s->out_buf[s->out_ptr], sz);
s->out_ptr += sz;
if (!is_rndis(s)) {
if (p->iov.size < 64) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf, s->out_ptr);
s->out_ptr = 0;
}
return;
}
len = le32_to_cpu(msg->MessageLength);
if (s->out_ptr < 8 || s->out_ptr < len) {
return;
}
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength);
if (offs + size <= len)
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
}
s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,078 | static void usb_net_handle_destroy(USBDevice *dev)
{
USBNetState *s = (USBNetState *) dev;
/* TODO: remove the nd_table[] entry */
rndis_clear_responsequeue(s);
qemu_del_nic(s->nic);
}
| DoS | 0 | static void usb_net_handle_destroy(USBDevice *dev)
{
USBNetState *s = (USBNetState *) dev;
/* TODO: remove the nd_table[] entry */
rndis_clear_responsequeue(s);
qemu_del_nic(s->nic);
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,079 | static void usb_net_handle_reset(USBDevice *dev)
{
}
| DoS | 0 | static void usb_net_handle_reset(USBDevice *dev)
{
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,080 | static void usb_net_handle_statusin(USBNetState *s, USBPacket *p)
{
le32 buf[2];
if (p->iov.size < 8) {
p->status = USB_RET_STALL;
return;
}
buf[0] = cpu_to_le32(1);
buf[1] = cpu_to_le32(0);
usb_packet_copy(p, buf, 8);
if (!s->rndis_resp.tqh_first) {
p->status = USB_RET_NAK;
}
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: interrupt poll len %zu return %d",
p->iov.size, p->status);
iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", p->status);
#endif
}
| DoS | 0 | static void usb_net_handle_statusin(USBNetState *s, USBPacket *p)
{
le32 buf[2];
if (p->iov.size < 8) {
p->status = USB_RET_STALL;
return;
}
buf[0] = cpu_to_le32(1);
buf[1] = cpu_to_le32(0);
usb_packet_copy(p, buf, 8);
if (!s->rndis_resp.tqh_first) {
p->status = USB_RET_NAK;
}
#ifdef TRAFFIC_DEBUG
fprintf(stderr, "usbnet: interrupt poll len %zu return %d",
p->iov.size, p->status);
iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", p->status);
#endif
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,081 | static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
{
Error *local_err = NULL;
USBDevice *dev;
QemuOpts *opts;
int idx;
opts = qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false);
if (!opts) {
return NULL;
}
qemu_opt_set(opts, "type", "nic", &error_abort);
qemu_opt_set(opts, "model", "usb", &error_abort);
idx = net_client_init(opts, 0, &local_err);
if (local_err) {
error_report_err(local_err);
return NULL;
}
dev = usb_create(bus, "usb-net");
qdev_set_nic_properties(&dev->qdev, &nd_table[idx]);
return dev;
}
| DoS | 0 | static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
{
Error *local_err = NULL;
USBDevice *dev;
QemuOpts *opts;
int idx;
opts = qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false);
if (!opts) {
return NULL;
}
qemu_opt_set(opts, "type", "nic", &error_abort);
qemu_opt_set(opts, "model", "usb", &error_abort);
idx = net_client_init(opts, 0, &local_err);
if (local_err) {
error_report_err(local_err);
return NULL;
}
dev = usb_create(bus, "usb-net");
qdev_set_nic_properties(&dev->qdev, &nd_table[idx]);
return dev;
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,082 | static void usb_net_instance_init(Object *obj)
{
USBDevice *dev = USB_DEVICE(obj);
USBNetState *s = USB_NET(dev);
device_add_bootindex_property(obj, &s->conf.bootindex,
"bootindex", "/ethernet-phy@0",
&dev->qdev, NULL);
}
| DoS | 0 | static void usb_net_instance_init(Object *obj)
{
USBDevice *dev = USB_DEVICE(obj);
USBNetState *s = USB_NET(dev);
device_add_bootindex_property(obj, &s->conf.bootindex,
"bootindex", "/ethernet-phy@0",
&dev->qdev, NULL);
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,083 | static void usb_net_realize(USBDevice *dev, Error **errrp)
{
USBNetState *s = USB_NET(dev);
usb_desc_create_serial(dev);
usb_desc_init(dev);
s->rndis_state = RNDIS_UNINITIALIZED;
QTAILQ_INIT(&s->rndis_resp);
s->medium = 0; /* NDIS_MEDIUM_802_3 */
s->speed = 1000000; /* 100MBps, in 100Bps units */
s->media_state = 0; /* NDIS_MEDIA_STATE_CONNECTED */;
s->filter = 0;
s->vendorid = 0x1234;
s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
object_get_typename(OBJECT(s)), s->dev.qdev.id, s);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
"%02x%02x%02x%02x%02x%02x",
0x40,
s->conf.macaddr.a[1],
s->conf.macaddr.a[2],
s->conf.macaddr.a[3],
s->conf.macaddr.a[4],
s->conf.macaddr.a[5]);
usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac);
}
| DoS | 0 | static void usb_net_realize(USBDevice *dev, Error **errrp)
{
USBNetState *s = USB_NET(dev);
usb_desc_create_serial(dev);
usb_desc_init(dev);
s->rndis_state = RNDIS_UNINITIALIZED;
QTAILQ_INIT(&s->rndis_resp);
s->medium = 0; /* NDIS_MEDIUM_802_3 */
s->speed = 1000000; /* 100MBps, in 100Bps units */
s->media_state = 0; /* NDIS_MEDIA_STATE_CONNECTED */;
s->filter = 0;
s->vendorid = 0x1234;
s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
object_get_typename(OBJECT(s)), s->dev.qdev.id, s);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
"%02x%02x%02x%02x%02x%02x",
0x40,
s->conf.macaddr.a[1],
s->conf.macaddr.a[2],
s->conf.macaddr.a[3],
s->conf.macaddr.a[4],
s->conf.macaddr.a[5]);
usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac);
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,084 | static void usb_net_register_types(void)
{
type_register_static(&net_info);
usb_legacy_register(TYPE_USB_NET, "net", usb_net_init);
}
| DoS | 0 | static void usb_net_register_types(void)
{
type_register_static(&net_info);
usb_legacy_register(TYPE_USB_NET, "net", usb_net_init);
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,085 | static void usb_net_reset_in_buf(USBNetState *s)
{
s->in_ptr = s->in_len = 0;
qemu_flush_queued_packets(qemu_get_queue(s->nic));
}
| DoS | 0 | static void usb_net_reset_in_buf(USBNetState *s)
{
s->in_ptr = s->in_len = 0;
qemu_flush_queued_packets(qemu_get_queue(s->nic));
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,086 | static void usbnet_cleanup(NetClientState *nc)
{
USBNetState *s = qemu_get_nic_opaque(nc);
s->nic = NULL;
}
| DoS | 0 | static void usbnet_cleanup(NetClientState *nc)
{
USBNetState *s = qemu_get_nic_opaque(nc);
s->nic = NULL;
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,087 | static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
USBNetState *s = qemu_get_nic_opaque(nc);
uint8_t *in_buf = s->in_buf;
size_t total_size = size;
if (!s->dev.config) {
return -1;
}
if (is_rndis(s)) {
if (s->rndis_state != RNDIS_DATA_INITIALIZED) {
return -1;
}
total_size += sizeof(struct rndis_packet_msg_type);
}
if (total_size > sizeof(s->in_buf)) {
return -1;
}
/* Only accept packet if input buffer is empty */
if (s->in_len > 0) {
return 0;
}
if (is_rndis(s)) {
struct rndis_packet_msg_type *msg;
msg = (struct rndis_packet_msg_type *)in_buf;
memset(msg, 0, sizeof(struct rndis_packet_msg_type));
msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
msg->MessageLength = cpu_to_le32(size + sizeof(*msg));
msg->DataOffset = cpu_to_le32(sizeof(*msg) - 8);
msg->DataLength = cpu_to_le32(size);
/* msg->OOBDataOffset;
* msg->OOBDataLength;
* msg->NumOOBDataElements;
* msg->PerPacketInfoOffset;
* msg->PerPacketInfoLength;
* msg->VcHandle;
* msg->Reserved;
*/
in_buf += sizeof(*msg);
}
memcpy(in_buf, buf, size);
s->in_len = total_size;
s->in_ptr = 0;
return size;
}
| DoS | 0 | static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
USBNetState *s = qemu_get_nic_opaque(nc);
uint8_t *in_buf = s->in_buf;
size_t total_size = size;
if (!s->dev.config) {
return -1;
}
if (is_rndis(s)) {
if (s->rndis_state != RNDIS_DATA_INITIALIZED) {
return -1;
}
total_size += sizeof(struct rndis_packet_msg_type);
}
if (total_size > sizeof(s->in_buf)) {
return -1;
}
/* Only accept packet if input buffer is empty */
if (s->in_len > 0) {
return 0;
}
if (is_rndis(s)) {
struct rndis_packet_msg_type *msg;
msg = (struct rndis_packet_msg_type *)in_buf;
memset(msg, 0, sizeof(struct rndis_packet_msg_type));
msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
msg->MessageLength = cpu_to_le32(size + sizeof(*msg));
msg->DataOffset = cpu_to_le32(sizeof(*msg) - 8);
msg->DataLength = cpu_to_le32(size);
/* msg->OOBDataOffset;
* msg->OOBDataLength;
* msg->NumOOBDataElements;
* msg->PerPacketInfoOffset;
* msg->PerPacketInfoLength;
* msg->VcHandle;
* msg->Reserved;
*/
in_buf += sizeof(*msg);
}
memcpy(in_buf, buf, size);
s->in_len = total_size;
s->in_ptr = 0;
return size;
}
| @@ -654,7 +654,8 @@ typedef struct USBNetState {
static int is_rndis(USBNetState *s)
{
- return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
+ return s->dev.config ?
+ s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE : 0;
}
static int ndis_query(USBNetState *s, uint32_t oid, | null | null | null |
10,088 | static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
int completion)
{
int dir;
size_t len = 0;
const char *str = NULL;
int pid;
int ret;
int i;
USBDevice *dev;
USBEndpoint *ep;
struct ohci_iso_td iso_td;
uint32_t addr;
uint16_t starting_frame;
int16_t relative_frame_number;
int frame_count;
uint32_t start_offset, next_offset, end_offset = 0;
uint32_t start_addr, end_addr;
addr = ed->head & OHCI_DPTR_MASK;
if (ohci_read_iso_td(ohci, addr, &iso_td)) {
trace_usb_ohci_iso_td_read_failed(addr);
ohci_die(ohci);
return 0;
}
starting_frame = OHCI_BM(iso_td.flags, TD_SF);
frame_count = OHCI_BM(iso_td.flags, TD_FC);
relative_frame_number = USUB(ohci->frame_number, starting_frame);
trace_usb_ohci_iso_td_head(
ed->head & OHCI_DPTR_MASK, ed->tail & OHCI_DPTR_MASK,
iso_td.flags, iso_td.bp, iso_td.next, iso_td.be,
ohci->frame_number, starting_frame,
frame_count, relative_frame_number);
trace_usb_ohci_iso_td_head_offset(
iso_td.offset[0], iso_td.offset[1],
iso_td.offset[2], iso_td.offset[3],
iso_td.offset[4], iso_td.offset[5],
iso_td.offset[6], iso_td.offset[7]);
if (relative_frame_number < 0) {
trace_usb_ohci_iso_td_relative_frame_number_neg(relative_frame_number);
return 1;
} else if (relative_frame_number > frame_count) {
/* ISO TD expired - retire the TD to the Done Queue and continue with
the next ISO TD of the same ED */
trace_usb_ohci_iso_td_relative_frame_number_big(relative_frame_number,
frame_count);
OHCI_SET_BM(iso_td.flags, TD_CC, OHCI_CC_DATAOVERRUN);
ed->head &= ~OHCI_DPTR_MASK;
ed->head |= (iso_td.next & OHCI_DPTR_MASK);
iso_td.next = ohci->done;
ohci->done = addr;
i = OHCI_BM(iso_td.flags, TD_DI);
if (i < ohci->done_count)
ohci->done_count = i;
if (ohci_put_iso_td(ohci, addr, &iso_td)) {
ohci_die(ohci);
return 1;
}
return 0;
}
dir = OHCI_BM(ed->flags, ED_D);
switch (dir) {
case OHCI_TD_DIR_IN:
str = "in";
pid = USB_TOKEN_IN;
break;
case OHCI_TD_DIR_OUT:
str = "out";
pid = USB_TOKEN_OUT;
break;
case OHCI_TD_DIR_SETUP:
str = "setup";
pid = USB_TOKEN_SETUP;
break;
default:
trace_usb_ohci_iso_td_bad_direction(dir);
return 1;
}
if (!iso_td.bp || !iso_td.be) {
trace_usb_ohci_iso_td_bad_bp_be(iso_td.bp, iso_td.be);
return 1;
}
start_offset = iso_td.offset[relative_frame_number];
next_offset = iso_td.offset[relative_frame_number + 1];
if (!(OHCI_BM(start_offset, TD_PSW_CC) & 0xe) ||
((relative_frame_number < frame_count) &&
!(OHCI_BM(next_offset, TD_PSW_CC) & 0xe))) {
trace_usb_ohci_iso_td_bad_cc_not_accessed(start_offset, next_offset);
return 1;
}
if ((relative_frame_number < frame_count) && (start_offset > next_offset)) {
trace_usb_ohci_iso_td_bad_cc_overrun(start_offset, next_offset);
return 1;
}
if ((start_offset & 0x1000) == 0) {
start_addr = (iso_td.bp & OHCI_PAGE_MASK) |
(start_offset & OHCI_OFFSET_MASK);
} else {
start_addr = (iso_td.be & OHCI_PAGE_MASK) |
(start_offset & OHCI_OFFSET_MASK);
}
if (relative_frame_number < frame_count) {
end_offset = next_offset - 1;
if ((end_offset & 0x1000) == 0) {
end_addr = (iso_td.bp & OHCI_PAGE_MASK) |
(end_offset & OHCI_OFFSET_MASK);
} else {
end_addr = (iso_td.be & OHCI_PAGE_MASK) |
(end_offset & OHCI_OFFSET_MASK);
}
} else {
/* Last packet in the ISO TD */
end_addr = iso_td.be;
}
if ((start_addr & OHCI_PAGE_MASK) != (end_addr & OHCI_PAGE_MASK)) {
len = (end_addr & OHCI_OFFSET_MASK) + 0x1001
- (start_addr & OHCI_OFFSET_MASK);
} else {
len = end_addr - start_addr + 1;
}
if (len && dir != OHCI_TD_DIR_IN) {
if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, len,
DMA_DIRECTION_TO_DEVICE)) {
ohci_die(ohci);
return 1;
}
}
if (!completion) {
bool int_req = relative_frame_number == frame_count &&
OHCI_BM(iso_td.flags, TD_DI) == 0;
dev = ohci_find_device(ohci, OHCI_BM(ed->flags, ED_FA));
ep = usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN));
usb_packet_setup(&ohci->usb_packet, pid, ep, 0, addr, false, int_req);
usb_packet_addbuf(&ohci->usb_packet, ohci->usb_buf, len);
usb_handle_packet(dev, &ohci->usb_packet);
if (ohci->usb_packet.status == USB_RET_ASYNC) {
usb_device_flush_ep_queue(dev, ep);
return 1;
}
}
if (ohci->usb_packet.status == USB_RET_SUCCESS) {
ret = ohci->usb_packet.actual_length;
} else {
ret = ohci->usb_packet.status;
}
trace_usb_ohci_iso_td_so(start_offset, end_offset, start_addr, end_addr,
str, len, ret);
/* Writeback */
if (dir == OHCI_TD_DIR_IN && ret >= 0 && ret <= len) {
/* IN transfer succeeded */
if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, ret,
DMA_DIRECTION_FROM_DEVICE)) {
ohci_die(ohci);
return 1;
}
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_NOERROR);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE, ret);
} else if (dir == OHCI_TD_DIR_OUT && ret == len) {
/* OUT transfer succeeded */
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_NOERROR);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE, 0);
} else {
if (ret > (ssize_t) len) {
trace_usb_ohci_iso_td_data_overrun(ret, len);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_DATAOVERRUN);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE,
len);
} else if (ret >= 0) {
trace_usb_ohci_iso_td_data_underrun(ret);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_DATAUNDERRUN);
} else {
switch (ret) {
case USB_RET_IOERROR:
case USB_RET_NODEV:
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_DEVICENOTRESPONDING);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE,
0);
break;
case USB_RET_NAK:
case USB_RET_STALL:
trace_usb_ohci_iso_td_nak(ret);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_STALL);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE,
0);
break;
default:
trace_usb_ohci_iso_td_bad_response(ret);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_UNDEXPETEDPID);
break;
}
}
}
if (relative_frame_number == frame_count) {
/* Last data packet of ISO TD - retire the TD to the Done Queue */
OHCI_SET_BM(iso_td.flags, TD_CC, OHCI_CC_NOERROR);
ed->head &= ~OHCI_DPTR_MASK;
ed->head |= (iso_td.next & OHCI_DPTR_MASK);
iso_td.next = ohci->done;
ohci->done = addr;
i = OHCI_BM(iso_td.flags, TD_DI);
if (i < ohci->done_count)
ohci->done_count = i;
}
if (ohci_put_iso_td(ohci, addr, &iso_td)) {
ohci_die(ohci);
}
return 1;
}
| DoS | 0 | static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
int completion)
{
int dir;
size_t len = 0;
const char *str = NULL;
int pid;
int ret;
int i;
USBDevice *dev;
USBEndpoint *ep;
struct ohci_iso_td iso_td;
uint32_t addr;
uint16_t starting_frame;
int16_t relative_frame_number;
int frame_count;
uint32_t start_offset, next_offset, end_offset = 0;
uint32_t start_addr, end_addr;
addr = ed->head & OHCI_DPTR_MASK;
if (ohci_read_iso_td(ohci, addr, &iso_td)) {
trace_usb_ohci_iso_td_read_failed(addr);
ohci_die(ohci);
return 0;
}
starting_frame = OHCI_BM(iso_td.flags, TD_SF);
frame_count = OHCI_BM(iso_td.flags, TD_FC);
relative_frame_number = USUB(ohci->frame_number, starting_frame);
trace_usb_ohci_iso_td_head(
ed->head & OHCI_DPTR_MASK, ed->tail & OHCI_DPTR_MASK,
iso_td.flags, iso_td.bp, iso_td.next, iso_td.be,
ohci->frame_number, starting_frame,
frame_count, relative_frame_number);
trace_usb_ohci_iso_td_head_offset(
iso_td.offset[0], iso_td.offset[1],
iso_td.offset[2], iso_td.offset[3],
iso_td.offset[4], iso_td.offset[5],
iso_td.offset[6], iso_td.offset[7]);
if (relative_frame_number < 0) {
trace_usb_ohci_iso_td_relative_frame_number_neg(relative_frame_number);
return 1;
} else if (relative_frame_number > frame_count) {
/* ISO TD expired - retire the TD to the Done Queue and continue with
the next ISO TD of the same ED */
trace_usb_ohci_iso_td_relative_frame_number_big(relative_frame_number,
frame_count);
OHCI_SET_BM(iso_td.flags, TD_CC, OHCI_CC_DATAOVERRUN);
ed->head &= ~OHCI_DPTR_MASK;
ed->head |= (iso_td.next & OHCI_DPTR_MASK);
iso_td.next = ohci->done;
ohci->done = addr;
i = OHCI_BM(iso_td.flags, TD_DI);
if (i < ohci->done_count)
ohci->done_count = i;
if (ohci_put_iso_td(ohci, addr, &iso_td)) {
ohci_die(ohci);
return 1;
}
return 0;
}
dir = OHCI_BM(ed->flags, ED_D);
switch (dir) {
case OHCI_TD_DIR_IN:
str = "in";
pid = USB_TOKEN_IN;
break;
case OHCI_TD_DIR_OUT:
str = "out";
pid = USB_TOKEN_OUT;
break;
case OHCI_TD_DIR_SETUP:
str = "setup";
pid = USB_TOKEN_SETUP;
break;
default:
trace_usb_ohci_iso_td_bad_direction(dir);
return 1;
}
if (!iso_td.bp || !iso_td.be) {
trace_usb_ohci_iso_td_bad_bp_be(iso_td.bp, iso_td.be);
return 1;
}
start_offset = iso_td.offset[relative_frame_number];
next_offset = iso_td.offset[relative_frame_number + 1];
if (!(OHCI_BM(start_offset, TD_PSW_CC) & 0xe) ||
((relative_frame_number < frame_count) &&
!(OHCI_BM(next_offset, TD_PSW_CC) & 0xe))) {
trace_usb_ohci_iso_td_bad_cc_not_accessed(start_offset, next_offset);
return 1;
}
if ((relative_frame_number < frame_count) && (start_offset > next_offset)) {
trace_usb_ohci_iso_td_bad_cc_overrun(start_offset, next_offset);
return 1;
}
if ((start_offset & 0x1000) == 0) {
start_addr = (iso_td.bp & OHCI_PAGE_MASK) |
(start_offset & OHCI_OFFSET_MASK);
} else {
start_addr = (iso_td.be & OHCI_PAGE_MASK) |
(start_offset & OHCI_OFFSET_MASK);
}
if (relative_frame_number < frame_count) {
end_offset = next_offset - 1;
if ((end_offset & 0x1000) == 0) {
end_addr = (iso_td.bp & OHCI_PAGE_MASK) |
(end_offset & OHCI_OFFSET_MASK);
} else {
end_addr = (iso_td.be & OHCI_PAGE_MASK) |
(end_offset & OHCI_OFFSET_MASK);
}
} else {
/* Last packet in the ISO TD */
end_addr = iso_td.be;
}
if ((start_addr & OHCI_PAGE_MASK) != (end_addr & OHCI_PAGE_MASK)) {
len = (end_addr & OHCI_OFFSET_MASK) + 0x1001
- (start_addr & OHCI_OFFSET_MASK);
} else {
len = end_addr - start_addr + 1;
}
if (len && dir != OHCI_TD_DIR_IN) {
if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, len,
DMA_DIRECTION_TO_DEVICE)) {
ohci_die(ohci);
return 1;
}
}
if (!completion) {
bool int_req = relative_frame_number == frame_count &&
OHCI_BM(iso_td.flags, TD_DI) == 0;
dev = ohci_find_device(ohci, OHCI_BM(ed->flags, ED_FA));
ep = usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN));
usb_packet_setup(&ohci->usb_packet, pid, ep, 0, addr, false, int_req);
usb_packet_addbuf(&ohci->usb_packet, ohci->usb_buf, len);
usb_handle_packet(dev, &ohci->usb_packet);
if (ohci->usb_packet.status == USB_RET_ASYNC) {
usb_device_flush_ep_queue(dev, ep);
return 1;
}
}
if (ohci->usb_packet.status == USB_RET_SUCCESS) {
ret = ohci->usb_packet.actual_length;
} else {
ret = ohci->usb_packet.status;
}
trace_usb_ohci_iso_td_so(start_offset, end_offset, start_addr, end_addr,
str, len, ret);
/* Writeback */
if (dir == OHCI_TD_DIR_IN && ret >= 0 && ret <= len) {
/* IN transfer succeeded */
if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, ret,
DMA_DIRECTION_FROM_DEVICE)) {
ohci_die(ohci);
return 1;
}
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_NOERROR);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE, ret);
} else if (dir == OHCI_TD_DIR_OUT && ret == len) {
/* OUT transfer succeeded */
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_NOERROR);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE, 0);
} else {
if (ret > (ssize_t) len) {
trace_usb_ohci_iso_td_data_overrun(ret, len);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_DATAOVERRUN);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE,
len);
} else if (ret >= 0) {
trace_usb_ohci_iso_td_data_underrun(ret);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_DATAUNDERRUN);
} else {
switch (ret) {
case USB_RET_IOERROR:
case USB_RET_NODEV:
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_DEVICENOTRESPONDING);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE,
0);
break;
case USB_RET_NAK:
case USB_RET_STALL:
trace_usb_ohci_iso_td_nak(ret);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_STALL);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_SIZE,
0);
break;
default:
trace_usb_ohci_iso_td_bad_response(ret);
OHCI_SET_BM(iso_td.offset[relative_frame_number], TD_PSW_CC,
OHCI_CC_UNDEXPETEDPID);
break;
}
}
}
if (relative_frame_number == frame_count) {
/* Last data packet of ISO TD - retire the TD to the Done Queue */
OHCI_SET_BM(iso_td.flags, TD_CC, OHCI_CC_NOERROR);
ed->head &= ~OHCI_DPTR_MASK;
ed->head |= (iso_td.next & OHCI_DPTR_MASK);
iso_td.next = ohci->done;
ohci->done = addr;
i = OHCI_BM(iso_td.flags, TD_DI);
if (i < ohci->done_count)
ohci->done_count = i;
}
if (ohci_put_iso_td(ohci, addr, &iso_td)) {
ohci_die(ohci);
}
return 1;
}
| @@ -1347,16 +1347,6 @@ static void ohci_frame_boundary(void *opaque)
*/
static int ohci_bus_start(OHCIState *ohci)
{
- ohci->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
- ohci_frame_boundary,
- ohci);
-
- if (ohci->eof_timer == NULL) {
- trace_usb_ohci_bus_eof_timer_failed(ohci->name);
- ohci_die(ohci);
- return 0;
- }
-
trace_usb_ohci_start(ohci->name);
/* Delay the first SOF event by one frame time as
@@ -1373,11 +1363,7 @@ static int ohci_bus_start(OHCIState *ohci)
static void ohci_bus_stop(OHCIState *ohci)
{
trace_usb_ohci_stop(ohci->name);
- if (ohci->eof_timer) {
- timer_del(ohci->eof_timer);
- timer_free(ohci->eof_timer);
- }
- ohci->eof_timer = NULL;
+ timer_del(ohci->eof_timer);
}
/* Sets a flag in a port status register but only set it if the port is
@@ -1907,6 +1893,9 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
usb_packet_init(&ohci->usb_packet);
ohci->async_td = 0;
+
+ ohci->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
+ ohci_frame_boundary, ohci);
}
#define TYPE_PCI_OHCI "pci-ohci"
@@ -1976,6 +1965,9 @@ static void usb_ohci_exit(PCIDevice *dev)
if (!ohci->masterbus) {
usb_bus_release(&s->bus);
}
+
+ timer_del(s->eof_timer);
+ timer_free(s->eof_timer);
}
static void usb_ohci_reset_pci(DeviceState *d)
@@ -2041,23 +2033,13 @@ static bool ohci_eof_timer_needed(void *opaque)
{
OHCIState *ohci = opaque;
- return ohci->eof_timer != NULL;
-}
-
-static int ohci_eof_timer_pre_load(void *opaque)
-{
- OHCIState *ohci = opaque;
-
- ohci_bus_start(ohci);
-
- return 0;
+ return timer_pending(ohci->eof_timer);
}
static const VMStateDescription vmstate_ohci_eof_timer = {
.name = "ohci-core/eof-timer",
.version_id = 1,
.minimum_version_id = 1,
- .pre_load = ohci_eof_timer_pre_load,
.needed = ohci_eof_timer_needed,
.fields = (VMStateField[]) {
VMSTATE_TIMER_PTR(eof_timer, OHCIState), | null | null | null |
10,089 | DEFUN (vpnv4_network,
vpnv4_network_cmd,
"network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
"Specify a network to announce via BGP\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
"BGP tag\n"
"tag value\n")
{
return bgp_static_set_vpnv4 (vty, argv[0], argv[1], argv[2]);
}
| DoS Exec Code Overflow | 0 | DEFUN (vpnv4_network,
vpnv4_network_cmd,
"network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
"Specify a network to announce via BGP\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
"BGP tag\n"
"tag value\n")
{
return bgp_static_set_vpnv4 (vty, argv[0], argv[1], argv[2]);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,090 | DEFUN (no_vpnv4_network,
no_vpnv4_network_cmd,
"no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
NO_STR
"Specify a network to announce via BGP\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
"BGP tag\n"
"tag value\n")
{
return bgp_static_unset_vpnv4 (vty, argv[0], argv[1], argv[2]);
}
| DoS Exec Code Overflow | 0 | DEFUN (no_vpnv4_network,
no_vpnv4_network_cmd,
"no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
NO_STR
"Specify a network to announce via BGP\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
"BGP tag\n"
"tag value\n")
{
return bgp_static_unset_vpnv4 (vty, argv[0], argv[1], argv[2]);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,091 | DEFUN (show_ip_bgp_vpnv4_all,
show_ip_bgp_vpnv4_all_cmd,
"show ip bgp vpnv4 all",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n")
{
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 0);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_all,
show_ip_bgp_vpnv4_all_cmd,
"show ip bgp vpnv4 all",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n")
{
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 0);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,092 | DEFUN (show_ip_bgp_vpnv4_rd,
show_ip_bgp_vpnv4_rd_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n")
{
int ret;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 0);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_rd,
show_ip_bgp_vpnv4_rd_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n")
{
int ret;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 0);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,093 | DEFUN (show_ip_bgp_vpnv4_all_tags,
show_ip_bgp_vpnv4_all_tags_cmd,
"show ip bgp vpnv4 all tags",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Display BGP tags for prefixes\n")
{
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 1);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_all_tags,
show_ip_bgp_vpnv4_all_tags_cmd,
"show ip bgp vpnv4 all tags",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Display BGP tags for prefixes\n")
{
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 1);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,094 | DEFUN (show_ip_bgp_vpnv4_rd_tags,
show_ip_bgp_vpnv4_rd_tags_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Display BGP tags for prefixes\n")
{
int ret;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 1);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_rd_tags,
show_ip_bgp_vpnv4_rd_tags_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Display BGP tags for prefixes\n")
{
int ret;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 1);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,095 | DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes,
show_ip_bgp_vpnv4_all_neighbor_routes_cmd,
"show ip bgp vpnv4 all neighbors A.B.C.D routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display routes learned from neighbor\n")
{
union sockunion su;
struct peer *peer;
int ret;
ret = str2sockunion (argv[0], &su);
if (ret < 0)
{
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_neighbor, &su, 0);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes,
show_ip_bgp_vpnv4_all_neighbor_routes_cmd,
"show ip bgp vpnv4 all neighbors A.B.C.D routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display routes learned from neighbor\n")
{
union sockunion su;
struct peer *peer;
int ret;
ret = str2sockunion (argv[0], &su);
if (ret < 0)
{
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_neighbor, &su, 0);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,096 | DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes,
show_ip_bgp_vpnv4_rd_neighbor_routes_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display routes learned from neighbor\n")
{
int ret;
union sockunion su;
struct peer *peer;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
ret = str2sockunion (argv[1], &su);
if (ret < 0)
{
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_neighbor, &su, 0);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes,
show_ip_bgp_vpnv4_rd_neighbor_routes_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display routes learned from neighbor\n")
{
int ret;
union sockunion su;
struct peer *peer;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
ret = str2sockunion (argv[1], &su);
if (ret < 0)
{
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_neighbor, &su, 0);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,097 | DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes,
show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd,
"show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display the routes advertised to a BGP neighbor\n")
{
int ret;
struct peer *peer;
union sockunion su;
ret = str2sockunion (argv[0], &su);
if (ret < 0)
{
vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, NULL);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes,
show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd,
"show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display the routes advertised to a BGP neighbor\n")
{
int ret;
struct peer *peer;
union sockunion su;
ret = str2sockunion (argv[0], &su);
if (ret < 0)
{
vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, NULL);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,098 | DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display the routes advertised to a BGP neighbor\n")
{
int ret;
struct peer *peer;
struct prefix_rd prd;
union sockunion su;
ret = str2sockunion (argv[1], &su);
if (ret < 0)
{
vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, &prd);
}
| DoS Exec Code Overflow | 0 | DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display the routes advertised to a BGP neighbor\n")
{
int ret;
struct peer *peer;
struct prefix_rd prd;
union sockunion su;
ret = str2sockunion (argv[1], &su);
if (ret < 0)
{
vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, &prd);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
10,099 | bgp_mplsvpn_init (void)
{
install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
}
| DoS Exec Code Overflow | 0 | bgp_mplsvpn_init (void)
{
install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
}
| @@ -101,6 +101,7 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
pnt = packet->nlri;
lim = pnt + packet->length;
+#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
@@ -108,17 +109,38 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
/* Fetch prefix length. */
prefixlen = *pnt++;
- p.family = AF_INET;
+ p.family = afi2family (packet->afi);
psize = PSIZE (prefixlen);
-
- if (prefixlen < 88)
- {
- zlog_err ("prefix length is less than 88: %d", prefixlen);
- return -1;
- }
-
+
+ /* sanity check against packet data */
+ if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
+ {
+ zlog_err ("prefix length (%d) is less than 88"
+ " or larger than received (%u)",
+ prefixlen, (uint)(lim-pnt));
+ return -1;
+ }
+
+ /* sanity check against storage for the IP address portion */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
+ {
+ zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
+ return -1;
+ }
+
+ /* Sanity check against max bitlen of the address family */
+ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
+ {
+ zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
+ prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
+ p.family, prefix_blen (&p));
+ return -1;
+
+ }
+
/* Copyr label to prefix. */
- tagpnt = pnt;;
+ tagpnt = pnt;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
@@ -137,8 +159,9 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
return -1;
}
- p.prefixlen = prefixlen - 88;
- memcpy (&p.u.prefix, pnt + 11, psize - 11);
+ p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
+ memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
+ psize - VPN_PREFIXLEN_MIN_BYTES);
#if 0
if (type == RD_TYPE_AS)
@@ -149,9 +172,6 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
- if (pnt + psize > lim)
- return -1;
-
if (attr)
bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
@@ -159,12 +179,12 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
-
/* Packet length consistency check. */
if (pnt != lim)
return -1;
-
+
return 0;
+#undef VPN_PREFIXLEN_MIN_BYTES
}
int | CWE-119 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.