Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Sun, 19 Jan 2020 19:09:19
Message-Id: 1579457756.1c6dcbf136e0cfd7613dc696d482028453ee306b.grobian@gentoo
1 commit: 1c6dcbf136e0cfd7613dc696d482028453ee306b
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 19 18:15:56 2020 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 19 18:15:56 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1c6dcbf1
7
8 libq/tree: help for Coverity 206550 String not null terminated
9
10 the zalloc on buffer + 1 size should ensure null-termination, but
11 Coverity doesn't quite see this, so explicitly null-terminate the
12 string, thereby slightly optimising zalloc away for plain malloc
13
14 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
15
16 libq/tree.c | 3 ++-
17 1 file changed, 2 insertions(+), 1 deletion(-)
18
19 diff --git a/libq/tree.c b/libq/tree.c
20 index 9645237..dc6ee61 100644
21 --- a/libq/tree.c
22 +++ b/libq/tree.c
23 @@ -1164,13 +1164,14 @@ tree_pkg_metadata(tree_pkg_ctx *pkg_ctx)
24 }
25
26 len = sizeof(*ret) + s.st_size + 1;
27 - p = xbuf = xzalloc(len);
28 + p = xbuf = xmalloc(len);
29 if ((off_t)fread(p, 1, s.st_size, f) != s.st_size) {
30 free(p);
31 fclose(f);
32 pkg_ctx->fd = -1;
33 return NULL;
34 }
35 + p[s.st_size] = '\0';
36
37 ret = xmalloc(sizeof(*ret));
38 ret->email = NULL;