]> git.itanic.dy.fi Git - rrdd/blobdiff - onewire_parser.c
onewire_parser: Fix crash caused by off by one memory allocation
[rrdd] / onewire_parser.c
index 937400baf6b007acd929e63db0a8d9ba2b03881a..decc133e940eda7fcabc8bfc9d7ef5121061af0a 100644 (file)
@@ -23,13 +23,15 @@ static struct owparser_state *allocate_parser_state(const char **datastr)
 {
        int i;
 
-       /* Count how many sensor entries we need */
+       /*
+        * Count how many sensor entries we need. First entry belongs
+        * to server address or mount point and last one is NULL. So
+        * the index final is the count of actual valid sensor
+        * entries.
+        */
        for (i = 0; datastr[i]; i++)
                ;
 
-       /* The first entry belongs to server address or mount point */
-       i--;
-
        return calloc(sizeof(struct owparser_state), i);
 }