From: Tobias Stoeckmann Date: Fri, 13 Oct 2017 17:25:01 +0000 (+0200) Subject: babl: always end strncpy strings with NUL X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~139^2^2~72 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=541300d74abd65ed9c729b707b02b2d983e3b670;p=babl.git babl: always end strncpy strings with NUL The function strncpy(3) does not guarantee to end the destination string with NUL character if not enough space was available. This could happen on systems which allow paths which are longer than 4096 characters. Signed-off-by: Tobias Stoeckmann --- diff --git a/babl/babl-cache.c b/babl/babl-cache.c index fa3f387..4954e4b 100644 --- a/babl/babl-cache.c +++ b/babl/babl-cache.c @@ -37,6 +37,7 @@ mk_ancestry_iter (const char *path) { char copy[4096]; strncpy (copy, path, 4096); + copy[sizeof (copy) - 1] = '\0'; if (strrchr (copy, '/')) { *strrchr (copy, '/') = '\0'; @@ -63,6 +64,7 @@ mk_ancestry (const char *path) { char copy[4096]; strncpy (copy, path, 4096); + copy[sizeof (copy) - 1] = '\0'; #ifdef _WIN32 for (char *c = copy; *c; c++) if (*c == '\\') @@ -77,6 +79,7 @@ static const char *fish_cache_path (void) static char path[4096]; strncpy (path, FALLBACK_CACHE_PATH, 4096); + path[sizeof (path) - 1] = '\0'; #ifndef _WIN32 if (getenv ("XDG_CACHE_HOME")) sprintf (path, "%s/babl/babl-fishes", getenv("XDG_CACHE_HOME"));