*s = 0;
- if (attr->first != NULL) {
- at = attr->first->data;
- *s = *(char*)at->data;
+ if (attr->first == NULL) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
+ at = attr->first->data;
+ if (at->size != 1) {
+ ret = ERR_BADREPLY;
+ goto end;
}
+ *s = *(char*)at->data;
end:
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
sb = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (sb->port <= sa->ports)
ports[sb->port - 1] = sb->bitrate;
}
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
pb = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (pb->port > sa->ports)
continue;
else if (at->attr == ATTR_BITRATE_INPUT)
at = attr->first->data;
am = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (am->outport == 0) {
memset(ports, 0, 1 + sa->ports);
} else if (am->outport > 0 && at->size >= 1 + sa->ports) {
}
-void extractSwitchAttributes (struct swi_attr *sa, const List *l)
+int extractSwitchAttributes (struct swi_attr *sa, const List *l)
{
const ListNode *ln;
const struct attr *at;
for (ln = l->first; ln != NULL; ln = ln->next) {
at = ln->data;
+ if (at->size == 0)
+ return -EMSGSIZE;
switch (at->attr) {
break;
case ATTR_END:
- return;
+ return 0;
}
}
+
+
+ return 0;
}
int writeRequest (struct ngadmin *nga, List *attr);
-void extractSwitchAttributes (struct swi_attr *sa, const List *l);
+int extractSwitchAttributes (struct swi_attr *sa, const List *l);
#endif
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
ps = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (ps->port <= sa->ports)
ports[ps->port - 1] = ps->status;
}
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
aps = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (aps->port <= sa->ports) {
ps[aps->port -1].recv = aps->recv;
ps[aps->port -1].sent = aps->sent;
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
acr = at->data;
- if (at->size == sizeof(struct attr_cabletest_result) && acr->port == ct[i].port) {
+ if (at->size != sizeof(struct attr_cabletest_result)) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
+ if (acr->port == ct[i].port) {
ct[i].v1 = acr->v1;
ct[i].v2 = acr->v2;
break;
*s = 0;
- if (attr->first != NULL) {
- at = attr->first->data;
- *s = *(char*)at->data;
+ if (attr->first == NULL) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
+ at = attr->first->data;
+ if (at->size != 1) {
+ ret = ERR_BADREPLY;
+ goto end;
}
+ *s = *(char*)at->data;
end:
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
aq = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (aq->port <= sa->ports)
ports[aq->port - 1] = aq->prio;
}
if (sa == NULL)
return ERR_MEM;
- extractSwitchAttributes(sa, attr);
+ if (extractSwitchAttributes(sa, attr) == 0)
+ pushBackList(swiList, sa);
+
clearList(attr, (void(*)(void*))freeAttr);
- pushBackList(swiList, sa);
}
nga->swi_count = swiList->count;
goto end;
}
at = attr->first->data;
+ if (at->size != 1) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
*t =(int)*(char*)at->data;
end:
for (ln = attr->first; ln != NULL; ln = ln->next) {
at = ln->data;
ap = at->data;
+ if (at->size == 0) {
+ ret = ERR_BADREPLY;
+ goto end;
+ }
if (ap->port <= sa->ports)
ports[ap->port - 1] = ap->vlan;
}