shithub: scc

Download patch

ref: cb1b6c86fe82527f4c3c5f8f11ea4f5e4ae6a350
parent: 43e3393ad7bb57bef89fedfe2cd4f48c33588bcc
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Oct 5 03:39:27 EDT 2021

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).

--- a/src/libc/stdio/fclose.c
+++ b/src/libc/stdio/fclose.c
@@ -22,7 +22,7 @@
 
 	if (fp->flags & _IOALLOC) {
 		free(fp->buf);
-		fp->buf = NULL;
+		fp->rp = fp->wp = fp->lp = fp->buf = NULL;
 	}
 
 	fp->flags &= ~(_IOWRITE | _IOREAD | _IORW |