commit: ba9f14cf0aebb606e2818a9d21863763709a1fcb
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 16 18:46:24 2021 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Dec 16 18:46:24 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ba9f14cf
main: fix memory overwrite in strincr_var
This caused memory corruption, and a subsequent crash in qmanifest.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
main.c | 5 +++--
tests/qmanifest/dotest | 8 +++++---
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/main.c b/main.c
index 37ba036..06c52b7 100644
--- a/main.c
+++ b/main.c
@@ -265,9 +265,10 @@ strincr_var(const char *name, const char *s, char **value,
size_t *value_len)
if (haddashstar && len < *value_len) {
p = *value;
*p = '\0'; /* in case len == 0 */
+ } else if (haddashstar) {
+ p = *value = xrealloc(*value, len + 1);
} else {
- *value = xrealloc(*value,
- (haddashstar ? (*value_len +
1) : 0) + len + 1);
+ *value = xrealloc(*value, *value_len + 1 + len + 1);
p = &(*value)[*value_len];
if (*value_len > 0)
*p++ = ' ';
diff --git a/tests/qmanifest/dotest b/tests/qmanifest/dotest
index 4031c8b..e7f6d05 100755
--- a/tests/qmanifest/dotest
+++ b/tests/qmanifest/dotest
@@ -12,14 +12,14 @@ mktmpdir
test() {
local num=$1 exp=$2 ret=0
shift 2
- eval "$@" > manifest 2>&1 || ret=$?
+ eval "$*" > manifest 2>&1 || ret=$?
sed -i -e '/^checked [0-9]/s/ in [0-9.]\+s$//' manifest
if ! diff -u ${as}/manifest${num}.good manifest; then
tfail "output does not match"
[[ -e gpgme.log ]] && cat gpgme.log
fi
if [[ ${exp} -ne ${ret} ]] ; then
- tfail "exit code (${ret}) does not match expected (${exp}) for
test ${num}"
+ tfail "exit code (${ret}) does not match expected (${exp}) for
test ${num} (args: $*)"
fi
tend $? "$*"
}
@@ -74,6 +74,8 @@ set +e
if gpg_import "${as}"/key.gpg qmanifest ; then
set -e
+tend 0 "gpg import key"
+
# make it a fully valid tree
rm testtree/my-cat/mypackage/unrecorded-file
# drop ROOT, we'll work here in T
@@ -82,7 +84,7 @@ SIGNAS=0x3D695C8C0F87966B62DC5AFCDCFABA8E07F52261
KEYPASS=qmanifest
export GPGME_DEBUG=9:${PWD}/gpgme.log
rm -f gpgme.log
-test 06 0 "echo ${KEYPASS} | qmanifest -g -s ${SIGNAS} -p testtree"
+test 06 0 "qmanifest -g -s ${SIGNAS} -p testtree <<< ${KEYPASS}"
# validate the just generated tree
rm -f gpgme.log