upnpsoap.c: Fix atoi() on null pointers

This commit is contained in:
Thomas Bernard 2012-10-05 00:19:26 +02:00
parent 7227e55dba
commit c0d4c9d24a
2 changed files with 36 additions and 14 deletions

View File

@ -1,6 +1,7 @@
$Id: Changelog.txt,v 1.318 2012/10/04 22:11:55 nanard Exp $
2012/10/03:
Fix atoi() on null pointer in upnpsoap.c
ENABLE_HTTP_DATE : add a Date: header to all HTTP responses
2012/09/27:

View File

@ -1,4 +1,4 @@
/* $Id: upnpsoap.c,v 1.111 2012/09/27 11:54:57 nanard Exp $ */
/* $Id: upnpsoap.c,v 1.113 2012/10/04 22:10:26 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -486,15 +486,15 @@ AddAnyPortMapping(struct upnphttp * h, const char * action)
if(leaseduration == 0)
leaseduration = 604800;
eport = (unsigned short)atoi(ext_port);
iport = (unsigned short)atoi(int_port);
if (!int_ip)
if (!int_ip || !ext_port || !int_port)
{
ClearNameValueList(&data);
SoapError(h, 402, "Invalid Args");
return;
}
eport = (unsigned short)atoi(ext_port);
iport = (unsigned short)atoi(int_port);
#ifndef SUPPORT_REMOTEHOST
#ifdef UPNP_STRICT
if (r_host && (strlen(r_host) > 0) && (0 != strcmp(r_host, "*")))
@ -723,17 +723,25 @@ DeletePortMappingRange(struct upnphttp * h, const char * action)
"</u:DeletePortMappingRangeResponse>";
struct NameValueParserData data;
const char * protocol;
const char * startport_s, * endport_s;
unsigned short startport, endport;
int manage;
/*int manage;*/
unsigned short * port_list;
unsigned int i, number = 0;
UNUSED(action);
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
startport = (unsigned short)atoi(GetValueFromNameValueList(&data, "NewStartPort"));
endport = (unsigned short)atoi(GetValueFromNameValueList(&data, "NewEndPort"));
startport_s = GetValueFromNameValueList(&data, "NewStartPort");
endport_s = GetValueFromNameValueList(&data, "NewEndPort");
protocol = GetValueFromNameValueList(&data, "NewProtocol");
manage = atoi(GetValueFromNameValueList(&data, "NewManage"));
/*manage = atoi(GetValueFromNameValueList(&data, "NewManage"));*/
if(startport_s == NULL || endport_s == NULL || protocol == NULL) {
SoapError(h, 402, "Invalid Args");
ClearNameValueList(&data);
return;
}
startport = (unsigned short)atoi(startport_s);
endport = (unsigned short)atoi(endport_s);
/* possible errors :
606 - Action not authorized
@ -870,19 +878,32 @@ GetListOfPortMappings(struct upnphttp * h, const char * action)
unsigned int leaseduration = 0;
struct NameValueParserData data;
const char * startport_s, * endport_s;
unsigned short startport, endport;
const char * protocol;
int manage;
/*int manage;*/
const char * number_s;
int number;
unsigned short * port_list;
unsigned int i, list_size = 0;
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
startport = (unsigned short)atoi(GetValueFromNameValueList(&data, "NewStartPort"));
endport = (unsigned short)atoi(GetValueFromNameValueList(&data, "NewEndPort"));
startport_s = GetValueFromNameValueList(&data, "NewStartPort");
endport_s = GetValueFromNameValueList(&data, "NewEndPort");
protocol = GetValueFromNameValueList(&data, "NewProtocol");
manage = atoi(GetValueFromNameValueList(&data, "NewManage"));
number = atoi(GetValueFromNameValueList(&data, "NewNumberOfPorts"));
/*manage_s = GetValueFromNameValueList(&data, "NewManage");*/
number_s = GetValueFromNameValueList(&data, "NewNumberOfPorts");
if(startport_s == NULL || endport_s == NULL || protocol == NULL ||
number_s == NULL) {
SoapError(h, 402, "Invalid Args");
ClearNameValueList(&data);
return;
}
startport = (unsigned short)atoi(startport_s);
endport = (unsigned short)atoi(endport_s);
/*manage = atoi(manage_s);*/
number = atoi(number_s);
if(number == 0) number = 1000; /* return up to 1000 mappings by default */
if(startport > endport)