summaryrefslogtreecommitdiff
path: root/lib/header.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2021-02-18 11:22:41 +0200
committerPanu Matilainen <pmatilai@redhat.com>2021-03-22 12:12:12 +0200
commit2490efaae9a56018adb346a4e0bc12b8c60713cd (patch)
treef97c8eb98510fd1722fb04a07decc027fe99e8c8 /lib/header.c
parent55a444f826584a1d4e55fd470b4ad223d16af2e8 (diff)
downloadrpm-2490efaae9a56018adb346a4e0bc12b8c60713cd.tar.gz
Fix regression from commit 165330b7bf0757e30fa8a6de9998a564fb62796f
With the changed logic, the if-clause can fall through without ever initializing s. The exit code condition is getting more complicated now so move it to helper variable, assume failure for a safe default. Fixes: 165330b7bf0757e30fa8a6de9998a564fb62796f (cherry picked from commit 34f28c1492240c0a02b0abb13af7f1870197e41d)
Diffstat (limited to 'lib/header.c')
-rw-r--r--lib/header.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/header.c b/lib/header.c
index 82b90eda0..6af48e61a 100644
--- a/lib/header.c
+++ b/lib/header.c
@@ -423,7 +423,8 @@ unsigned headerSizeof(Header h, int magicp)
static inline int strtaglen(const char *str, rpm_count_t c, const char *end)
{
const char *start = str;
- const char *s;
+ const char *s = NULL;
+ int len = -1; /* assume failure */
if (end) {
while (end > start && (s = memchr(start, '\0', end-start))) {
@@ -438,7 +439,11 @@ static inline int strtaglen(const char *str, rpm_count_t c, const char *end)
start = s + 1;
}
}
- return (c > 0) ? -1 : (s - str + 1);
+
+ if (s != NULL && c == 0)
+ len = s - str + 1;
+
+ return len;
}
/**