From b3e3ceb9160799e6e9537efced41d2d51e15b9a0 Mon Sep 17 00:00:00 2001 From: ngie Date: Fri, 10 Jun 2016 18:10:32 +0000 Subject: [PATCH] MFC r299510: r299510 (by cem): libmp: Fix trivial buffer overrun fgetln yields a non-NUL-terminated buffer and its length. This routine attempted to NUL-terminate it, but did not allocate space for the NUL. So, allocate space for the NUL. CID: 1017457 git-svn-id: svn://svn.freebsd.org/base/stable/10@301806 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libmp/mpasbn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libmp/mpasbn.c b/lib/libmp/mpasbn.c index bc5556dfb..2656124c4 100644 --- a/lib/libmp/mpasbn.c +++ b/lib/libmp/mpasbn.c @@ -286,10 +286,10 @@ mp_min(MINT *mp) line = fgetln(stdin, &linelen); if (line == NULL) MPERR(("min")); - nline = malloc(linelen); + nline = malloc(linelen + 1); if (nline == NULL) MPERR(("min")); - strncpy(nline, line, linelen); + memcpy(nline, line, linelen); nline[linelen] = '\0'; rmp = _dtom("min", nline); _movem("min", rmp, mp); -- 2.45.0