summaryrefslogtreecommitdiff
path: root/lib/libedit/el.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2019-07-23 10:18:52 +0000
committerchristos <christos@NetBSD.org>2019-07-23 10:18:52 +0000
commit5439fdddbda55fffc2348d840a67d8fa35914b2d (patch)
treee64ac73f44bc4cf138a93e6faa0545d9d6508e59 /lib/libedit/el.c
parentd0d4388f4c0dff4fc2533cdd4920677859e0b914 (diff)
PR/54399: Sören Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b)) to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
Diffstat (limited to 'lib/libedit/el.c')
-rw-r--r--lib/libedit/el.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index 9a4773653e0..9ae7af3533d 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.98 2019/04/26 16:56:57 christos Exp $ */
+/* $NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
-__RCSID("$NetBSD: el.c,v 1.98 2019/04/26 16:56:57 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -71,13 +71,11 @@ libedit_private EditLine *
el_init_internal(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
int fdin, int fdout, int fderr, int flags)
{
- EditLine *el = el_malloc(sizeof(*el));
+ EditLine *el = el_calloc(1, sizeof(*el));
if (el == NULL)
return NULL;
- memset(el, 0, sizeof(EditLine));
-
el->el_infile = fin;
el->el_outfile = fout;
el->el_errfile = ferr;
@@ -534,7 +532,7 @@ el_source(EditLine *el, const char *fname)
if ((ptr = getenv("HOME")) == NULL)
return -1;
plen += strlen(ptr);
- if ((path = el_malloc(plen * sizeof(*path))) == NULL)
+ if ((path = el_calloc(plen, sizeof(*path))) == NULL)
return -1;
(void)snprintf(path, plen, "%s%s", ptr,
elpath + (*ptr == '\0'));