]> git.itanic.dy.fi Git - rrdd/blobdiff - onewire_parser.c
onewire_parser: Ensure proper strng NULL handling
[rrdd] / onewire_parser.c
index 54ba71fbf6f7d13d0294499ed13b466dd6d129b2..b33ee9f696850066e79623d9627cd30c55961d89 100644 (file)
@@ -117,6 +117,9 @@ static int make_uncached(char *path, size_t len)
        if (strstr(path, "/uncached/"))
                return 0;
 
+       p1[sizeof(p1) - 1] = '\0';
+       p2[sizeof(p2) - 1] = '\0';
+
        /*
         * Naively assume the "uncached" string can be put after the
         * first slash
@@ -130,8 +133,8 @@ static int make_uncached(char *path, size_t len)
        *p = 0;
        p++;
 
-       strncpy(p1, path, sizeof(p1));
-       strncpy(p2, p, sizeof(p2));
+       strncpy(p1, path, sizeof(p1) - 1);
+       strncpy(p2, p, sizeof(p2) - 1);
        snprintf(path, len, "%s/uncached/%s", p1, p2);
 
        return 0;