Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Mar 2021 22:22:02 GMT
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 18f3c5fe9207 - main - usr.sbin/services_mkdb: plug memory leak when line was blank.
Message-ID:  <202103302222.12UMM28e002451@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by delphij:

URL: https://cgit.FreeBSD.org/src/commit/?id=18f3c5fe9207fbd19360b8ddb23ba10a5ad3df68

commit 18f3c5fe9207fbd19360b8ddb23ba10a5ad3df68
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2021-03-30 22:21:37 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2021-03-30 22:21:37 +0000

    usr.sbin/services_mkdb: plug memory leak when line was blank.
    
    Reviewed by:    bapt
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D29370
---
 usr.sbin/services_mkdb/uniq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/services_mkdb/uniq.c b/usr.sbin/services_mkdb/uniq.c
index 330a09fc10e1..c78b01ef27c5 100644
--- a/usr.sbin/services_mkdb/uniq.c
+++ b/usr.sbin/services_mkdb/uniq.c
@@ -120,12 +120,13 @@ comp(const char *origline, char **compline, size_t *len)
 	for (p = (const unsigned char *)origline; l && *p && isspace(*p);
 	    p++, l--)
 		continue;
+	if (*p == '\0' || l == 0)
+		return 0;
+
 	if ((cline = malloc(l + 1)) == NULL)
 		err(1, "Cannot allocate %zu bytes", l + 1);
 	(void)memcpy(cline, p, l);
 	cline[l] = '\0';
-	if (*cline == '\0')
-		return 0;
 
 	complen = 0;
 	hasalnum = 0;
@@ -155,6 +156,11 @@ comp(const char *origline, char **compline, size_t *len)
 		--complen;
 	}
 	*q = '\0';
+	if (!hasalnum) {
+		free(cline);
+		cline = NULL;
+		complen = 0;
+	}
 	*compline = cline;
 	*len = complen;
 	return hasalnum;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103302222.12UMM28e002451>