http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71849

Revision: 71849
Author:   platonides
Date:     2010-08-28 11:16:27 +0000 (Sat, 28 Aug 2010)

Log Message:
-----------
Be more robust in case we are given commands with wrong or missing parameters.

Modified Paths:
--------------
    trunk/extensions/PoolCounter/daemon/locks.c

Modified: trunk/extensions/PoolCounter/daemon/locks.c
===================================================================
--- trunk/extensions/PoolCounter/daemon/locks.c 2010-08-28 11:06:51 UTC (rev 
71848)
+++ trunk/extensions/PoolCounter/daemon/locks.c 2010-08-28 11:16:27 UTC (rev 
71849)
@@ -26,6 +26,22 @@
 #define DOUBLE_LLIST_DEL(this) do { (this)->prev->next = (this)->next; 
(this)->next->prev = (this)->prev; } while (0)
 #define DOUBLE_LLIST_ADD(parent,child) do { (child)->prev = (parent)->prev; 
(child)->next = (child)->prev->next /* parent */; (parent)->prev->next = 
(child); (parent)->prev = (child); } while(0);
 
+/* Converts a numeric text into an unsigned integer.
+ * Returns 0 if it's a NULL pointer or not a natural.
+ */
+unsigned atou(char const* astext)  {
+       int num = 0;
+       if (!astext) return 0;
+       
+       while ( *astext ) {
+               if ( *astext < '0' ) return 0;
+               if ( *astext > '9' ) return 0;
+               num = num * 10 + *astext - '0';
+               astext++;
+       }
+       return num;
+}
+
 char* process_line(struct client_data* cli_data, char* line, int line_len) {
        struct locks* l = &cli_data->client_locks;
        
@@ -37,10 +53,14 @@
                int for_anyone = line[6] != ' ';
                
                char* key = strtok( line + 7 + for_anyone, " " );
-               int workers = atoi( strtok(NULL, " ") );
-               int maxqueue = atoi( strtok(NULL, " ") );
-               int timeout = atoi( strtok(NULL, " ") );
+               unsigned workers = atou( strtok(NULL, " ") );
+               unsigned maxqueue = atou( strtok(NULL, " ") );
+               unsigned timeout = atou( strtok(NULL, " ") );
                
+               if ( !key || !workers || !maxqueue || !timeout ) {
+                       return "ERROR BAD_SYNTAX\n";
+               }
+               
                uint32_t hash_value = hash( key, strlen( key ), 0 );
                struct PoolCounter* pCounter;
                pCounter = hashtable_find( primary_hashtable, hash_value, key );



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to