From 247b9c8873ea60fd3d67c85eb730e088a35cdac5 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 1 Nov 2016 21:02:00 +0200 Subject: [PATCH] onewire_parser: Ensure proper strng NULL handling strncpy() call length argument must be one less than the actual buffer length. The final byte in buffer must be NULL, in case strncpy does not fill it with NULL itself. Signed-off-by: Timo Kokkonen --- onewire_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/onewire_parser.c b/onewire_parser.c index 54ba71f..b33ee9f 100644 --- a/onewire_parser.c +++ b/onewire_parser.c @@ -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; -- 2.45.0