1 |
commit: 5cdb5572185636cd5ab056241635d33b1b85fc98 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jan 19 19:18:48 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jan 19 19:18:48 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5cdb5572 |
7 |
|
8 |
libq/tree: help Coverity 206538 String not null terminated |
9 |
|
10 |
Coverity doesn't see that zalloc would have null-terminated. Upside, |
11 |
replace zalloc with malloc and just clear one (relevant) byte. |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
libq/tree.c | 3 ++- |
16 |
1 file changed, 2 insertions(+), 1 deletion(-) |
17 |
|
18 |
diff --git a/libq/tree.c b/libq/tree.c |
19 |
index c8ada5c..8da8120 100644 |
20 |
--- a/libq/tree.c |
21 |
+++ b/libq/tree.c |
22 |
@@ -689,10 +689,11 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx) |
23 |
goto err; |
24 |
|
25 |
len = sizeof(*ret) + s.st_size + 1; |
26 |
- ret = xzalloc(len); |
27 |
+ ret = xmalloc(len); |
28 |
ptr = (char*)ret + sizeof(*ret); |
29 |
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size) |
30 |
goto err; |
31 |
+ ptr[s.st_size] = '\0'; |
32 |
|
33 |
/* We have a block of key=value\n data. |
34 |
* KEY=VALUE\n |