]> git.itanic.dy.fi Git - rrdd/commitdiff
onewire_parser: Fix crash caused by off by one memory allocation
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 29 Jan 2017 15:03:00 +0000 (17:03 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 29 Jan 2017 15:03:00 +0000 (17:03 +0200)
The entries in sensor list always start with either server address or
mount point, which is not counted as a sensor. If we want to count the
actual number of sensors, we obviously need to add one more to the
last index number, otherwise we get one too small number for sensors
and allocate too little of memory for the parser state.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
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);
 }