summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2019-08-14 15:58:30 +0300
committerPanu Matilainen <pmatilai@redhat.com>2019-08-28 12:16:52 +0300
commit3fd2ad4ee136be222a242a50dc2658a6f9b4b3c9 (patch)
treec93d7dd9706cfff0f26c7b907cef1ff97b3173b8
parentc8fcc7d4ace1633e3eca478b7d6ecd6d34b85003 (diff)
downloadrpm-3fd2ad4ee136be222a242a50dc2658a6f9b4b3c9.tar.gz
Fix segfault regression on empty script or description at end of spec
More ripples from the parseLines() unification (commits 91e8d826e473c98209ba9db0ea06ab884557076c to 783e2dc0b424afdf0a5d2add368279cb63016897), the callers used to explicitly allocate an empty string buffer, but with lazy allocation from parseLines() they're getting NULL in the special circumstance of being last in the spec, and no "body". Specifically this happens with empty %description or scriptlet without a body, eg "%post -p /sbin/ldconfig". The script regression report + reproducer and a preliminary patch originally from RhBug:1732276 by nvwarr. (cherry picked from commit 99b9ded5dd7d1118aea528600fcf20ba89dbab9b)
-rw-r--r--build/parseDescription.c9
-rw-r--r--build/parseScript.c9
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/data/SPECS/mini.spec7
-rw-r--r--tests/rpmbuild.at13
5 files changed, 34 insertions, 5 deletions
diff --git a/build/parseDescription.c b/build/parseDescription.c
index 2b255b514..c0737c09c 100644
--- a/build/parseDescription.c
+++ b/build/parseDescription.c
@@ -21,6 +21,7 @@ int parseDescription(rpmSpec spec)
const char **argv = NULL;
const char *name = NULL;
const char *lang = RPMBUILD_DEFAULT_LANG;
+ const char *descr = "";
poptContext optCon = NULL;
struct poptOption optionsTable[] = {
{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
@@ -68,9 +69,13 @@ int parseDescription(rpmSpec spec)
goto exit;
}
- stripTrailingBlanksStringBuf(sb);
+ if (sb) {
+ stripTrailingBlanksStringBuf(sb);
+ descr = getStringBuf(sb);
+ }
+
if (addLangTag(spec, pkg->header,
- RPMTAG_DESCRIPTION, getStringBuf(sb), lang)) {
+ RPMTAG_DESCRIPTION, descr, lang)) {
nextPart = PART_ERROR;
}
diff --git a/build/parseScript.c b/build/parseScript.c
index b3128ee51..bdf6ab3fb 100644
--- a/build/parseScript.c
+++ b/build/parseScript.c
@@ -79,7 +79,7 @@ int parseScript(rpmSpec spec, int parsePart)
/* -p "<sh> <args>..." */
/* -f <file> */
- const char *p;
+ const char *p = "";
const char **progArgv = NULL;
int progArgc;
const char *partname = NULL;
@@ -354,8 +354,11 @@ int parseScript(rpmSpec spec, int parsePart)
if ((res = parseLines(spec, STRIP_NOTHING, NULL, &sb)) == PART_ERROR)
goto exit;
- stripTrailingBlanksStringBuf(sb);
- p = getStringBuf(sb);
+
+ if (sb) {
+ stripTrailingBlanksStringBuf(sb);
+ p = getStringBuf(sb);
+ }
#ifdef WITH_LUA
if (rstreq(progArgv[0], "<lua>")) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index baf9aacce..94ffd8da3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,6 +65,7 @@ EXTRA_DIST += data/SPECS/symlinktest.spec
EXTRA_DIST += data/SPECS/deptest.spec
EXTRA_DIST += data/SPECS/verifyscript.spec
EXTRA_DIST += data/SPECS/fakeshell.spec
+EXTRA_DIST += data/SPECS/mini.spec
EXTRA_DIST += data/SPECS/scripts.spec
EXTRA_DIST += data/SPECS/scriptfail.spec
EXTRA_DIST += data/SPECS/selfconflict.spec
diff --git a/tests/data/SPECS/mini.spec b/tests/data/SPECS/mini.spec
new file mode 100644
index 000000000..41b5ec1de
--- /dev/null
+++ b/tests/data/SPECS/mini.spec
@@ -0,0 +1,7 @@
+Name: mini
+Version: 1
+Release: 1
+License: k
+Summary: Minimal spec
+
+%description
diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at
index bf663843a..9f6803bb5 100644
--- a/tests/rpmbuild.at
+++ b/tests/rpmbuild.at
@@ -1598,3 +1598,16 @@ run rpmbuild \
[error: Bad source: ${TOPDIR}/SOURCES/hello-1.0.tar.gz: No such file or directory
])
AT_CLEANUP
+
+AT_SETUP([rpmbuild minimal spec])
+AT_KEYWORDS([build])
+AT_CHECK_UNQUOTED([
+rm -rf ${TOPDIR}
+
+run rpmbuild \
+ -bb --quiet "${abs_srcdir}"/data/SPECS/mini.spec
+],
+[0],
+[],
+[])
+AT_CLEANUP