From ab9246618b1d369cdba1140135dedb8affc5485e Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 23 Oct 2007 00:39:21 +0000 Subject: [PATCH] some clients chose to accidently send negative numwants --- opentracker.c | 1 + scan_urlencoded_query.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/opentracker.c b/opentracker.c index 41df0ee..cfa051a 100644 --- a/opentracker.c +++ b/opentracker.c @@ -511,6 +511,7 @@ ANNOUNCE_WORKAROUND: if(!byte_diff(data,7,"numwant")) { len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); if( ( len <= 0 ) || scan_fixed_int( data, len, &numwant ) ) HTTPERROR_400_PARAM; + if( numwant < 0 ) numwant = 50; if( numwant > 200 ) numwant = 200; } else if(!byte_diff(data,7,"compact")) { len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index 241a904..a78a697 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c @@ -78,8 +78,11 @@ ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_F } ssize_t scan_fixed_int( char *data, size_t len, int *tmp ) { + int minus = 0; *tmp = 0; + if( *data == '-' ) --len, ++data, ++minus; while( (len > 0) && (*data >= '0') && (*data <= '9') ) { --len; *tmp = 10**tmp + *data++-'0'; } + if( minus ) *tmp = -*tmp; return len; }