Added length checking (#1260)

Made the code clearer
This commit is contained in:
Philip Gladstone 2016-04-24 10:45:47 -04:00 committed by Marcel Stör
parent 25b4285c4d
commit 0472587c4c
1 changed files with 4 additions and 1 deletions

View File

@ -326,7 +326,7 @@ static int coap_request( lua_State* L, coap_method_t m )
stack++;
pesp_conn = cud->pesp_conn;
ip_addr_t ipaddr;
uint8_t host[32];
uint8_t host[64];
unsigned t;
if ( lua_isnumber(L, stack) )
@ -348,6 +348,9 @@ static int coap_request( lua_State* L, coap_method_t m )
coap_uri_t *uri = coap_new_uri(url, l); // should call free(uri) somewhere
if (uri == NULL)
return luaL_error( L, "uri wrong format." );
if (uri->host.length + 1 /* for the null */ > sizeof(host)) {
return luaL_error(L, "host too long");
}
pesp_conn->proto.udp->remote_port = uri->port;
NODE_DBG("UDP port is set: %d.\n", uri->port);