commit cb1b6c86fe82527f4c3c5f8f11ea4f5e4ae6a350
parent 43e3393ad7bb57bef89fedfe2cd4f48c33588bcc
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 |