Преглед изворни кода

confdata: fix invalid write

stndup will copy *up to* the size parameter, not allocate a buffer of
that size, so the buffer is not necessarily large enough to fit the
".old" extension.

Caught with glibc's MALLOC_CHECK_=3.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
Ben Boeckel пре 8 година
родитељ
комит
0074f6d29b
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      extra/config/confdata.c

+ 2 - 1
extra/config/confdata.c

@@ -814,7 +814,8 @@ next:
 	fclose(out);
 
 	if (*tmpname) {
-		dirname = strndup(basename, strlen(basename) + 4);
+		dirname = malloc(strlen(basename) + 4 + 1);
+		strcpy(dirname, basename);
 		strcat(dirname, ".old");
 		rename(newname, dirname);
 		free(dirname);