src/server/daemon/config.c

branch
webdav
changeset 339
f4a34b0869c7
parent 270
4cfaa02055cd
child 366
47bc686fafe4
--- a/src/server/daemon/config.c	Sat May 07 15:07:01 2022 +0200
+++ b/src/server/daemon/config.c	Sun May 08 10:33:41 2022 +0200
@@ -388,19 +388,41 @@
     }
     
     if(min.length != 0) {
-        poolcfg.min_threads = atoi(min.ptr);
+        int64_t value;
+        if(util_strtoint(min.ptr, &value)) {
+            poolcfg.min_threads = value;
+        } else {
+            log_ereport(LOG_MISCONFIG, "Threadpool: MinThreads not an integer");
+            return 1;
+        }
     }
     
     if(max.length != 0) {
-        poolcfg.max_threads = atoi(max.ptr);
+        int64_t value;
+        if(util_strtoint(max.ptr, &value)) {
+            poolcfg.max_threads = value;
+        } else {
+            log_ereport(LOG_MISCONFIG, "Threadpool: MaxThreads not an integer");
+            return 1;
+        }
     }
     
     if(stack.length != 0) {
-        poolcfg.stack_size = atoi(stack.ptr);
+        int64_t value;
+        if(util_strtoint(stack.ptr, &value)) {
+            poolcfg.stack_size = value;
+        } else {
+            log_ereport(LOG_MISCONFIG, "Threadpool: StackSize not an integer");
+        }
     }
     
     if(queue.length != 0) {
-        poolcfg.queue_size = atoi(queue.ptr);
+        int64_t value;
+        if(util_strtoint(queue.ptr, &value)) {
+            poolcfg.queue_size = value;
+        } else {
+            log_ereport(LOG_MISCONFIG, "Threadpool: QueueSize not an integer");
+        }
     }
     
     create_threadpool(name, &poolcfg);
@@ -408,6 +430,7 @@
     return 0;
 }
 
+#define EV_MAX_THREADS 2048
 int cfg_handle_eventhandler(ServerConfiguration *c, ConfigNode *obj) {
     EventHandlerConfig evcfg;
     
@@ -417,7 +440,17 @@
     
     evcfg.name = name;
     
-    evcfg.nthreads = atoi(threads.ptr);
+    int64_t value;
+    if(!util_strtoint(threads.ptr, &value)) {
+        log_ereport(LOG_MISCONFIG, "EventHandler: Threads: '%s' is not an integer", threads.ptr);
+        return 1;
+    }
+    if(value < 1 || value > EV_MAX_THREADS) {
+        log_ereport(LOG_MISCONFIG, "EventHandler: Invalid number of threads (1 .. %d)", EV_MAX_THREADS);
+        return 1;
+    }
+    
+    evcfg.nthreads = value;
     
     evcfg.isdefault = util_getboolean(isdefault.ptr, 0);
     
@@ -525,8 +558,18 @@
     scstr_t blck = serverconfig_directive_value(obj, SC("BlockingIO"));
     
     // TODO: use sstrdup_pool?
+    int64_t port_value;
+    if(!util_strtoint(port.ptr, &port_value)) {
+        log_ereport(LOG_MISCONFIG, "Listener: Invalid argument for parameter 'Port': '%s'", port.ptr);
+        return 1;
+    }
+    if(port_value < 1 || port_value > 65535) {
+        log_ereport(LOG_MISCONFIG, "Listener: Port number out of range (1 .. 65535)");
+        return 1;
+    }
+    
     lc.name = sstrdup(name);
-    lc.port = atoi(port.ptr);
+    lc.port = port_value;
     lc.vs = sstrdup(vs);
     lc.threadpool = sstrdup(thrp);
     

mercurial