]> granicus.if.org Git - cgit/commitdiff
truncate buffer before reading empty files
authorSimon Arlott <simon@fire.lp0.eu>
Sat, 7 Mar 2009 00:06:24 +0000 (00:06 +0000)
committerLars Hjemli <hjemli@gmail.com>
Tue, 18 Aug 2009 12:27:41 +0000 (14:27 +0200)
If readfile() reads an empty file, fgets() won't truncate the buffer
and it'll still contain the contents of the previously read file.

[lh: fixed similar issue in ui-repolist.c]

Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
scan-tree.c
ui-repolist.c

index cdafb02df6b51a9ea7bc82a94a59d18cf4389054..47f3988b3723673b0ed06b104f41822711db46cf 100644 (file)
@@ -42,6 +42,7 @@ char *readfile(const char *path)
 
        if (!(f = fopen(path, "r")))
                return NULL;
+       buf[0] = 0;
        fgets(buf, MAX_PATH, f);
        fclose(f);
        return buf;
index 2c13d5041b2a4931358b241b6316db3d96a9a6b5..3aedde5456f761fe58926bfef7e28f389975aa41 100644 (file)
@@ -23,6 +23,7 @@ time_t read_agefile(char *path)
 
        if (!(f = fopen(path, "r")))
                return -1;
+       buf[0] = 0;
        if (fgets(buf, sizeof(buf), f) == NULL)
                return -1;
        fclose(f);