commit:     5cdb5572185636cd5ab056241635d33b1b85fc98
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 19 19:18:48 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jan 19 19:18:48 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5cdb5572

libq/tree: help Coverity 206538 String not null terminated

Coverity doesn't see that zalloc would have null-terminated.  Upside,
replace zalloc with malloc and just clear one (relevant) byte.

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 c8ada5c..8da8120 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -689,10 +689,11 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
                goto err;
 
        len = sizeof(*ret) + s.st_size + 1;
-       ret = xzalloc(len);
+       ret = xmalloc(len);
        ptr = (char*)ret + sizeof(*ret);
        if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
                goto err;
+       ptr[s.st_size] = '\0';
 
        /* We have a block of key=value\n data.
         * KEY=VALUE\n

Reply via email to