[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
- [PATCH unionfs 0/3] Fix unionfs build errors, Sergey Bugaev, 2021/04/26
- [PATCH unionfs 3/3] Don't use strncat() with length derived from source string,
Sergey Bugaev <=
- Re: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string, Jessica Clarke, 2021/04/26
- Re: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string, Samuel Thibault, 2021/04/26
- Re: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string, Sergey Bugaev, 2021/04/26
- Re: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string, Samuel Thibault, 2021/04/26
- Re: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string, Sergey Bugaev, 2021/04/27
- Re: [PATCH unionfs 3/3] Don’t use strncat() with length derived from source string, Ivan Shmakov, 2021/04/27
- Re: [PATCH unionfs 3/3] Don't use strncat() with length derived from source string, Samuel Thibault, 2021/04/27
[PATCH unionfs 1/3] Implement MiG intran payload support, Sergey Bugaev, 2021/04/26
[PATCH unionfs 2/3] Add some missing includes, Sergey Bugaev, 2021/04/26