[babl] babl: always end strncpy strings with NUL



commit 541300d74abd65ed9c729b707b02b2d983e3b670
Author: Tobias Stoeckmann <tobias stoeckmann org>
Date:   Fri Oct 13 19:25:01 2017 +0200

    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 <tobias stoeckmann org>

 babl/babl-cache.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
---
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"));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]