From 286a45d4adfd427fcee5237412874a8d69b5e6e7 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Tue, 17 Apr 2007 03:55:20 +0000 Subject: [PATCH] * SF Tracker [ 1652827 ] UpnpRegisterRootDevice returned -104 Submitted By: Michael Andersen - miwer Issue was found to be related to sizeof (size_t) != sizeof (int) on AMD64 systems. Emil Ljungdahl's AMD64 patch has been applied along with some other fixes. Original user report follows: When I run upnpd I get the above mentioned error (UPNP_E_OUTOF_MEMORY). I've tried with 1.4.1 and 1.4.2-RC3, it's the same. I don't understand why, because I have plenty of RAM, and I even tried closing some applications, but it didn't help. $ upnpd eth1 br0 The following is logged in the /var/log/messages: Feb 6 01:33:47 server upnpd[6933]: Error registering the root device with descDocUrl: http://192.168.0.1:49152/gatedesc.xml Feb 6 01:33:47 server upnpd[6933]: UpnpRegisterRootDevice returned -104 I tried enabling debugging and it looks like it cannot allocate memory through the membuffer_append function. It's wierd because it's only a few bytes. Please note, that I enabled some extra debugging lines that were commented, in order to get more information. See attached files. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@154 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- ChangeLog | 28 ++++++++++++++++++++++++ THANKS | 1 + upnp/src/genlib/net/http/httpreadwrite.c | 23 ++++++++++--------- upnp/src/genlib/net/http/webserver.c | 2 +- upnp/src/genlib/net/uri/uri.c | 6 ++--- upnp/src/inc/http_client.h | 2 +- upnp/src/inc/membuffer.h | 21 ++++++------------ upnp/src/inc/uri.h | 10 ++++----- 8 files changed, 59 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index e31e82d..92722b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,34 @@ Version 1.4.4 Submitted By: Luke Kim - nereusuj Unix sleep is in seconds but WIN32 Sleep is in milliseconds. +2007-04-17 Marcelo Jimenez + * SF Tracker [ 1652827 ] UpnpRegisterRootDevice returned -104 + Submitted By: Michael Andersen - miwer + + Issue was found to be related to sizeof (size_t) != sizeof (int) + on AMD64 systems. Emil Ljungdahl's AMD64 patch has been applied along + with some other fixes. Original user report follows: + + When I run upnpd I get the above mentioned error (UPNP_E_OUTOF_MEMORY). + I've tried with 1.4.1 and 1.4.2-RC3, it's the same. I don't understand why, + because I have plenty of RAM, and I even tried closing some applications, + but it didn't help. + + $ upnpd eth1 br0 + + The following is logged in the /var/log/messages: + Feb 6 01:33:47 server upnpd[6933]: Error registering the root device with + descDocUrl: http://192.168.0.1:49152/gatedesc.xml + Feb 6 01:33:47 server upnpd[6933]: UpnpRegisterRootDevice returned -104 + + + I tried enabling debugging and it looks like it cannot allocate memory + through the membuffer_append function. It's wierd because it's only a few + bytes. + + Please note, that I enabled some extra debugging lines that were commented, + in order to get more information. See attached files. + ************************************************************************* Version 1.4.3 ************************************************************************* diff --git a/THANKS b/THANKS index 66def27..0f789a1 100644 --- a/THANKS +++ b/THANKS @@ -9,6 +9,7 @@ exempt of errors. - Arno Willig - Chaos - David Maass +- Emil Ljungdahl - Erik Johansson - Eric Tanguy - Erwan Velu diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index b684f82..c5f82f2 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -802,27 +802,30 @@ MakePostMessage( const char *url_str, "HOSTNAME : %s Length : %d\n", hoststr, hostlen ); ) - if( contentLength >= 0 ) { + if( contentLength >= 0 ) { ret_code = http_MakeMessage( request, 1, 1, - "QsbcDCUTNc", + "Q" "s" "bcDCU" "T" "Nc", HTTPMETHOD_POST, url->pathquery.buff, url->pathquery.size, - "HOST: ", hoststr, hostlen, + "HOST: ", + hoststr, hostlen, contentType, (off_t)contentLength ); } else if( contentLength == UPNP_USING_CHUNKED ) { ret_code = http_MakeMessage( request, 1, 1, - "QsbcDCUTKc", + "Q" "s" "bcDCU" "TKc", HTTPMETHOD_POST, url->pathquery.buff, url->pathquery.size, - "HOST: ", hoststr, hostlen, + "HOST: ", + hoststr, hostlen, contentType ); } else if( contentLength == UPNP_UNTIL_CLOSE ) { ret_code = http_MakeMessage( request, 1, 1, - "QsbcDCUTc", + "Q" "s" "bcDCU" "Tc", HTTPMETHOD_POST, url->pathquery.buff, url->pathquery.size, - "HOST: ", hoststr, hostlen, + "HOST: ", + hoststr, hostlen, contentType ); } else { ret_code = UPNP_E_INVALID_PARAM; @@ -1816,7 +1819,7 @@ http_MakeMessage( INOUT membuffer * buf, { char c; char *s = NULL; - int num; + size_t num; off_t bignum; size_t length; time_t *loc_time; @@ -1899,7 +1902,7 @@ http_MakeMessage( INOUT membuffer * buf, { num = ( int )va_arg( argp, int ); - sprintf( tempbuf, "%d", num ); + sprintf( tempbuf, "%zu", num ); if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) { goto error_handler; } @@ -2047,7 +2050,7 @@ http_MakeMessage( INOUT membuffer * buf, method = ( http_method_t ) va_arg( argp, http_method_t ); method_str = method_to_str( method ); url_str = ( const char * )va_arg( argp, const char * ); - num = ( int )va_arg( argp, int ); // length of url_str + num = ( size_t )va_arg( argp, size_t ); // length of url_str if (http_MakeMessage( buf, http_major_version, http_minor_version, diff --git a/upnp/src/genlib/net/http/webserver.c b/upnp/src/genlib/net/http/webserver.c index fe04bac..b59ba03 100644 --- a/upnp/src/genlib/net/http/webserver.c +++ b/upnp/src/genlib/net/http/webserver.c @@ -1207,7 +1207,7 @@ process_request( IN http_message_t * req, int resp_major, resp_minor; xboolean alias_grabbed; - int dummy; + size_t dummy; struct UpnpVirtualDirCallbacks *pVirtualDirCallback; print_http_headers( req ); diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index e614b81..fefc396 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -157,7 +157,7 @@ is_escaped( const char *in ) int replace_escaped( char *in, int index, - int *max ) + size_t *max ) { int tempInt = 0; char tempChar = 0; @@ -733,7 +733,7 @@ parse_scheme( const char *in, ************************************************************************/ int remove_escaped_chars( INOUT char *in, - INOUT int *size ) + INOUT size_t *size ) { int i = 0; @@ -1069,7 +1069,7 @@ parse_uri( const char *in, int parse_uri_and_unescape( char *in, int max, - uri_type * out ) + uri_type *out ) { int ret; diff --git a/upnp/src/inc/http_client.h b/upnp/src/inc/http_client.h index 11cad5c..16eb4aa 100644 --- a/upnp/src/inc/http_client.h +++ b/upnp/src/inc/http_client.h @@ -96,7 +96,7 @@ typedef struct SOCKET_BUFFER{ //holds a pointer into a larger array typedef struct TOKEN { char * buff; - int size; + size_t size; } token; diff --git a/upnp/src/inc/membuffer.h b/upnp/src/inc/membuffer.h index c9a61c9..ec9987b 100644 --- a/upnp/src/inc/membuffer.h +++ b/upnp/src/inc/membuffer.h @@ -51,8 +51,7 @@ typedef struct // memptr // note: Total length/capacity should not exceed MAX_INT typedef struct // membuffer { - char *buf; // mem buffer; must not write - // beyond buf[length-1] (read/write) + char *buf; // mem buffer; must not write beyond buf[length-1] (read/write) size_t length; // length of buffer (read-only) size_t capacity; // total allocated memory (read-only) size_t size_inc; // used to increase size; MUST be > 0; (read/write) @@ -148,8 +147,7 @@ int memptr_cmp_nocase( IN memptr* m, IN const char* s ); * * Note : ************************************************************************/ -int membuffer_set_size( INOUT membuffer* m, - IN size_t new_length ); +int membuffer_set_size( INOUT membuffer* m, IN size_t new_length ); /************************************************************************ * Function : membuffer_init @@ -200,8 +198,7 @@ void membuffer_destroy( INOUT membuffer* m ); * * Note : ************************************************************************/ -int membuffer_assign( INOUT membuffer* m, IN const void* buf, - IN size_t buf_len ); +int membuffer_assign( INOUT membuffer* m, IN const void* buf, IN size_t buf_len ); /************************************************************************ * Function : membuffer_assign_str @@ -237,8 +234,7 @@ int membuffer_assign_str( INOUT membuffer* m, IN const char* c_str ); * * Note : ************************************************************************/ -int membuffer_append( INOUT membuffer* m, IN const void* buf, - IN size_t buf_len ); +int membuffer_append( INOUT membuffer* m, IN const void* buf, IN size_t buf_len ); /************************************************************************ * Function : membuffer_append_str @@ -276,8 +272,7 @@ int membuffer_append_str( INOUT membuffer* m, IN const char* c_str ); * * Note : ************************************************************************/ -int membuffer_insert( INOUT membuffer* m, IN const void* buf, - IN size_t buf_len, int index ); +int membuffer_insert( INOUT membuffer* m, IN const void* buf, IN size_t buf_len, int index ); /************************************************************************ @@ -298,8 +293,7 @@ int membuffer_insert( INOUT membuffer* m, IN const void* buf, * * Note : ************************************************************************/ -void membuffer_delete( INOUT membuffer* m, IN int index, - IN size_t num_bytes ); +void membuffer_delete( INOUT membuffer* m, IN int index, IN size_t num_bytes ); /************************************************************************ @@ -336,8 +330,7 @@ char* membuffer_detach( INOUT membuffer* m ); * Note : 'new_buf' must be allocted using malloc or realloc so * that it can be freed using free() ************************************************************************/ -void membuffer_attach( INOUT membuffer* m, IN char* new_buf, - IN size_t buf_len ); +void membuffer_attach( INOUT membuffer* m, IN char* new_buf, IN size_t buf_len ); #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/upnp/src/inc/uri.h b/upnp/src/inc/uri.h index 31f6a99..229d653 100644 --- a/upnp/src/inc/uri.h +++ b/upnp/src/inc/uri.h @@ -87,7 +87,7 @@ enum uriType { absolute, relative }; * holds a pointer into a larger array */ typedef struct TOKEN { const char *buff; - int size; + size_t size; } token; @@ -124,7 +124,7 @@ typedef struct URL_LIST { * Parameters : * char * in ; string of characters * int index ; index at which to start checking the characters -* int *max ; +* size_t *max ; * * Description : Replaces an escaped sequence with its unescaped version * as in http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs) @@ -137,7 +137,7 @@ typedef struct URL_LIST { * string are shifted over, and NULL characters are placed at the * end of the string. ************************************************************************/ -int replace_escaped(char * in, int index, int *max); +int replace_escaped(char * in, int index, size_t *max); /************************************************************************ * Function : copy_URL_list @@ -303,7 +303,7 @@ int parse_hostport(const char *in, int max, hostport_type *out ); * * Parameters : * INOUT char *in ; string of characters to be modified -* INOUT int *size ; size limit for the number of characters +* INOUT size_t *size ; size limit for the number of characters * * Description : removes http escaped characters such as: "%20" and * replaces them with their character representation. i.e. @@ -315,7 +315,7 @@ int parse_hostport(const char *in, int max, hostport_type *out ); * * Note : ************************************************************************/ -int remove_escaped_chars(char *in,int *size); +int remove_escaped_chars(char *in, size_t *size); /************************************************************************ * Function : remove_dots