commit 7110c21ad718ac19314d54b996a29ce1ad9c1016
parent 492bd4733015403216b071fbbceb6bf88a8d19d5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 5 Oct 2021 07:39:27 +0200
libc: Avoid dangling pointers after fclose()
When a FILE is closed the pointers rp, rp and lp does
not make sense anymore, and they can point to a buffer
that is freed. Setting these pointers to NULL make
easier to detect wrong situations and return error in
those cases (for example in ungetc).
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libc/stdio/fclose.c b/src/libc/stdio/fclose.c
@@ -22,7 +22,7 @@ fclose(FILE *fp)
if (fp->flags & _IOALLOC) {
free(fp->buf);
- fp->buf = NULL;
+ fp->rp = fp->wp = fp->lp = fp->buf = NULL;
}
fp->flags &= ~(_IOWRITE | _IOREAD | _IORW |