bug-hurd
[Top][All Lists]
Advanced

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

[PATCH unionfs 3/3] Don't use strncat() with length derived from source


From: Sergey Bugaev
Subject: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string
Date: Mon, 26 Apr 2021 20:08:20 +0300

This fixes Wstringop-overflow and Wstringop-truncation GCC warnings.
See https://gcc.gnu.org/bugzilla//show_bug.cgi?id=88059

Also, fix a bug where a string was not properly null-terminated.
---
 lib.c  | 4 ++--
 stow.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib.c b/lib.c
index 01cdbd0..717979b 100644
--- a/lib.c
+++ b/lib.c
@@ -151,8 +151,8 @@ make_filepath (char *path, char *filename)
   if (filepath == NULL) 
     return NULL;
   
-  strncpy (filepath, path, length);
-  strncat (filepath, filename, strlen (filename));
+  strcpy (filepath, path);
+  strcat (filepath, filename);
 
   return filepath;
 }
diff --git a/stow.c b/stow.c
index 812d33b..adfcf53 100644
--- a/stow.c
+++ b/stow.c
@@ -282,14 +282,15 @@ stow_diradd (char *dir, int flags, struct patternlist 
*patternlist,
     {
       char *tmp;
 
-      tmp = (char *) malloc (dir_len + 1);
+      tmp = (char *) malloc (dir_len + 2);
 
       if (tmp == NULL)
        return ENOMEM;
 
-      strncpy (tmp, dir, dir_len);
+      strcpy (tmp, dir);
 
       tmp[dir_len] = '/';
+      tmp[dir_len + 1] = 0;
 
       dir = tmp;
     }
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]