Use recallocarray in getdelim/getline to clear memory on buffer resizes,
authorbrynet <brynet@openbsd.org>
Thu, 13 Apr 2017 18:36:51 +0000 (18:36 +0000)
committerbrynet <brynet@openbsd.org>
Thu, 13 Apr 2017 18:36:51 +0000 (18:36 +0000)
inspired by a similar change to fgetln.

ok deraadt millert

lib/libc/stdio/getdelim.c

index 0e0e338..d709a3d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: getdelim.c,v 1.5 2016/09/21 04:38:56 guenther Exp $   */
+/*     $OpenBSD: getdelim.c,v 1.6 2017/04/13 18:36:51 brynet Exp $     */
 /* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
 
 /*
@@ -103,7 +103,7 @@ getdelim(char **__restrict buf, size_t *__restrict buflen,
                                newlen++;
                        }
 
-                       newb = realloc(*buf, newlen);
+                       newb = recallocarray(*buf, *buflen, newlen, 1);
                        if (newb == NULL)
                                goto error;
                        *buf = newb;