chiark / gitweb /
ipif: eat_optionalstr: do not crash on end of argument list
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 Apr 2017 15:59:01 +0000 (16:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 Apr 2017 15:59:01 +0000 (16:59 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
ipif/service.c

index b401a5c..7821a46 100644 (file)
@@ -329,13 +329,17 @@ static char *eat_optionalstr(const char **argp,
                             const char *def) {
   ptrdiff_t len;
   const char *start= *argp;
-  const char *comma= strchr(start, ',');
-  if (comma) {
-    len= comma - start;
-    *argp= comma + 1;
+  if (!start) {
+    len = 0;
   } else {
-    len= strlen(start);
-    *argp= start + len;
+    const char *comma= strchr(start, ',');
+    if (comma) {
+      len= comma - start;
+      *argp= comma + 1;
+    } else {
+      len= strlen(start);
+      *argp= start + len;
+    }
   }
   if (!len) {
     start= def;