From d2256ac2d44b0a5be9c0b49ce4ce8e5f6821ce2a Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 1 Sep 2021 08:00:00 +0000
Subject: [PATCH 3/3] quotasys.c: fix strncpy usage
When quota is configured using --enable-werror, gcc -flto fails with
the following diagnostics:
In function 'strncpy',
inlined from 'sstrncpy' at common.c:107:2,
inlined from 'copy_mntoptarg' at quotasys.c:774:3,
inlined from 'copy_mntoptarg' at quotasys.c:769:13:
/usr/include/bits/string_fortified.h:91:10: error: '__builtin_strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
91 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^
quotasys.c: In function 'copy_mntoptarg':
quotasys.c:774:25: note: length computed here
774 | sstrncpy(buf, optarg, min(buflen, strlen(optarg) + 1));
| ^
This diagnostics is correct: strcpy() copies at most "len" bytes of the string
pointed to by "src", including the terminating null byte, to the buffer
pointed to by "dest".
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
quotasys.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/quotasys.c b/quotasys.c
index 885fb1f..3f50e32 100644
--- a/quotasys.c
+++ b/quotasys.c
@@ -771,7 +771,7 @@ static void copy_mntoptarg(char *buf, const char *optarg, int buflen)
char *sep = strchr(optarg, ',');
if (!sep)
- sstrncpy(buf, optarg, min(buflen, strlen(optarg) + 1));
+ sstrncpy(buf, optarg, buflen);
else
sstrncpy(buf, optarg, min(buflen, sep - optarg + 1));
}
--
2.31.1