Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miniupnpd: Several security issues were fixed in MiniUPnPd. #732

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion trunk/user/miniupnpd/miniupnpd-2.x/minixml.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ static void parseelt(struct xmlparser * p)
if (p->xml >= p->xmlend)
return;
}
if(memcmp(p->xml, "<![CDATA[", 9) == 0)
/* CDATA are at least 9 + 3 characters long : <![CDATA[ ]]> */
if((p->xmlend >= (p->xml + (9 + 3))) && (memcmp(p->xml, "<![CDATA[", 9) == 0))
{
/* CDATA handling */
p->xml += 9;
Expand Down
2 changes: 1 addition & 1 deletion trunk/user/miniupnpd/miniupnpd-2.x/pcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static const char * getPCPOpCodeStr(uint8_t opcode)
* buffers are same */
static void copyIPv6IfDifferent(void * dest, const void * src)
{
if(dest != src) {
if(dest != src && src != NULL) {
memcpy(dest, src, sizeof(struct in6_addr));
}
}
Expand Down
37 changes: 26 additions & 11 deletions trunk/user/miniupnpd/miniupnpd-2.x/upnpevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,34 @@ static void upnp_event_prepare(struct upnp_event_notify * obj)
l = 0;
}
obj->buffersize = 1024;
obj->buffer = malloc(obj->buffersize);
if(!obj->buffer) {
syslog(LOG_ERR, "%s: malloc returned NULL", "upnp_event_prepare");
if(xml) {
free(xml);
for (;;) {
obj->buffer = malloc(obj->buffersize);
if(!obj->buffer) {
syslog(LOG_ERR, "%s: malloc returned NULL", "upnp_event_prepare");
if(xml) {
free(xml);
}
obj->state = EError;
return;
}
obj->state = EError;
return;
obj->tosend = snprintf(obj->buffer, obj->buffersize, notifymsg,
obj->path, obj->addrstr, obj->portstr, l+2,
obj->sub->uuid, obj->sub->seq,
l, xml);
if (obj->tosend < 0) {
syslog(LOG_ERR, "%s: snprintf() failed", "upnp_event_prepare");
if(xml) {
free(xml);
}
obj->state = EError;
return;
} else if (obj->tosend < obj->buffersize) {
break; /* the buffer was large enough */
}
/* Try again with a buffer big enough */
free(obj->buffer);
obj->buffersize = obj->tosend + 1; /* reserve space for the final 0 */
}
obj->tosend = snprintf(obj->buffer, obj->buffersize, notifymsg,
obj->path, obj->addrstr, obj->portstr, l+2,
obj->sub->uuid, obj->sub->seq,
l, xml);
if(xml) {
free(xml);
xml = NULL;
Expand Down
4 changes: 4 additions & 0 deletions trunk/user/miniupnpd/miniupnpd-2.x/upnpredirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ upnp_redirect(const char * rhost, unsigned short eport,
"%hu->%s:%hu %s", eport, iaddr, iport, protocol);
return -3;
}

if (desc == NULL)
desc = ""; /* assume empty description */

/* IGDv1 (WANIPConnection:1 Service Template Version 1.01 / Nov 12, 2001)
* - 2.2.20.PortMappingDescription :
* Overwriting Previous / Existing Port Mappings:
Expand Down
4 changes: 1 addition & 3 deletions trunk/user/miniupnpd/miniupnpd-2.x/upnpreplyparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ ParseNameValue(const char * buffer, int bufsize,
struct NameValueParserData * data)
{
struct xmlparser parser;
data->l_head = NULL;
data->portListing = NULL;
data->portListingLength = 0;
memset(data, 0, sizeof(struct NameValueParserData));
/* init xmlparser object */
parser.xmlstart = buffer;
parser.xmlsize = bufsize;
Expand Down
7 changes: 7 additions & 0 deletions trunk/user/miniupnpd/miniupnpd-2.x/upnpsoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,13 @@ GetOutboundPinholeTimeout(struct upnphttp * h, const char * action, const char *
rem_port = GetValueFromNameValueList(&data, "RemotePort");
protocol = GetValueFromNameValueList(&data, "Protocol");

if (!int_port || !rem_port || !protocol)
{
ClearNameValueList(&data);
SoapError(h, 402, "Invalid Args");
return;
}

rport = (unsigned short)atoi(rem_port);
iport = (unsigned short)atoi(int_port);
/*proto = atoi(protocol);*/
Expand Down