@@ -250,6 +250,7 @@ static int parse_randomstring(char *line)
int num;
char *pstart, *pend, rndc[2];
unsigned int idx;
+ char str_orig[256];
char str[256];
size_t min_len;
@@ -262,6 +263,7 @@ again:
/* Truncate or use the smaller size passed */
min_len = strlen(line) < sizeof(str) ? strlen(line) : sizeof(str);
strncpy(str, pstart, min_len);
+ strncpy(str_orig, pstart, min_len);
pend = index(str, ']');
if (pstart == NULL) {
@@ -288,7 +290,7 @@ finished:
}
/* remote initial " */
while (str[0] == '"') {
- memcpy(str, str+1, sizeof(str)-1);
+ memcpy(str, str_orig+1, sizeof(str_orig)-1);
}
/* remote trailing " */
while (1) {
Fix this compilation warning: gcc -g -O2 -Wall -W -I. -DVERSION=\"4.00\" -DDATADIR=\"/usr/local/share\" `pkg-config --cflags libtirpc` -Wimplicit-fallthrough=2 -c -o child.o child.c In function ‘parse_randomstring’, inlined from ‘child_run’ at child.c:465:8: child.c:291:17: warning: ‘memcpy’ accessing 255 bytes at offsets 0 and 1 overlaps 254 bytes at offset 1 [-Wrestrict] 291 | memcpy(str, str+1, sizeof(str)-1); We fix this by using a copy of the string to a original string so to avoid having memcpy() overlap. Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> --- child.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)