commit: 1c6dcbf136e0cfd7613dc696d482028453ee306b
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 19 18:15:56 2020 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jan 19 18:15:56 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1c6dcbf1
libq/tree: help for Coverity 206550 String not null terminated
the zalloc on buffer + 1 size should ensure null-termination, but
Coverity doesn't quite see this, so explicitly null-terminate the
string, thereby slightly optimising zalloc away for plain malloc
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/tree.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libq/tree.c b/libq/tree.c
index 9645237..dc6ee61 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1164,13 +1164,14 @@ tree_pkg_metadata(tree_pkg_ctx *pkg_ctx)
}
len = sizeof(*ret) + s.st_size + 1;
- p = xbuf = xzalloc(len);
+ p = xbuf = xmalloc(len);
if ((off_t)fread(p, 1, s.st_size, f) != s.st_size) {
free(p);
fclose(f);
pkg_ctx->fd = -1;
return NULL;
}
+ p[s.st_size] = '\0';
ret = xmalloc(sizeof(*ret));
ret->email = NULL;