summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2020-10-23 14:02:35 +0200
committerPanu Matilainen <pmatilai@redhat.com>2020-12-10 13:28:07 +0200
commitfc94bbf6015e00b5ec99a03ee20a5469748a3742 (patch)
tree58d4f4df04c51f239fe138f59c9836e6225c937a
parentb589c11ab2bb1ec1a35ec116c01bfa767bb9efad (diff)
downloadrpm-fc94bbf6015e00b5ec99a03ee20a5469748a3742.tar.gz
Fix logic error in grabArgs()
If there was a \ at the end of the buffer, the code would return a pointer after the trailing \0 leading to unallocated memory access and weird results in some cases. See commit 817959609b95afe34ce0f7f6c3dc5d7d0d9a8470. (cherry picked from commit 6d7fa91949337c7a86bab3359b39558fdae07dce)
-rw-r--r--rpmio/macro.c2
-rw-r--r--tests/rpmmacro.at5
2 files changed, 6 insertions, 1 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c
index 0e63f68a4..35d896049 100644
--- a/rpmio/macro.c
+++ b/rpmio/macro.c
@@ -925,7 +925,7 @@ grabArgs(MacroBuf mb, const rpmMacroEntry me, const char * se,
splitQuoted(&argv, s, " \t");
free(s);
- cont = ((*lastc == '\0' || *lastc == '\n') && *(lastc-1) != '\\') ?
+ cont = (*lastc == '\0') || (*lastc == '\n' && *(lastc-1) != '\\') ?
lastc : lastc + 1;
}
diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at
index c67d96ede..873783153 100644
--- a/tests/rpmmacro.at
+++ b/tests/rpmmacro.at
@@ -179,6 +179,9 @@ runroot rpm \
--eval '%foo %{quote: 2 3 5} %{quote:%{nil}}' \
--eval '%foo x%{quote:y}z 123' \
--eval '%foo x%{quote:%{nil}}z' \
+ --eval '%foo 1 \
+bar' \
+ --eval '%foo 1 \' \
],
[0],
[1:"1"
@@ -190,6 +193,8 @@ runroot rpm \
2:" 2 3 5" ""
2:"xyz" "123"
1:"xz"
+2:"1" "\"bar
+2:"1" "\"
])
AT_CLEANUP