From e2f5034303ab4ea06a86c577b863d6c39946c884 Mon Sep 17 00:00:00 2001 From: Mooffie Date: Mon, 6 Mar 2017 19:15:03 +0200 Subject: [PATCH 1/4] Ticket #3786: extfs: rpm: fix test's "expected output". As will be explained in a following commit, our rpm helper has a bug stemming from the use of 'echo'. Before we fix it, we update the test's "expected output" to reflect the intended output (as it's currently reflects a faulty output). Signed-off-by: Mooffie --- .../src/vfs/extfs/helpers-list/data/rpm.custom.output | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/src/vfs/extfs/helpers-list/data/rpm.custom.output b/tests/src/vfs/extfs/helpers-list/data/rpm.custom.output index ea217c8d1..b04439347 100644 --- a/tests/src/vfs/extfs/helpers-list/data/rpm.custom.output +++ b/tests/src/vfs/extfs/helpers-list/data/rpm.custom.output @@ -1,4 +1,4 @@ --r--r--r-- 1 0 0 539 2017-01-05 00:00:00 HEADER +-r--r--r-- 1 0 0 597 2017-01-05 00:00:00 HEADER -r-xr-xr-x 1 0 0 39 2017-01-05 00:00:00 INSTALL -r-xr-xr-x 1 0 0 39 2017-01-05 00:00:00 UPGRADE dr-xr-xr-x 3 0 0 0 2017-01-05 00:00:00 INFO @@ -13,6 +13,7 @@ dr-xr-xr-x 3 0 0 0 2017-01-05 00:00:00 INFO -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/DISTRIBUTION -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/VENDOR -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/DESCRIPTION +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SUMMARY -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SCRIPTS/PRETRANS -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SCRIPTS/POSTTRANS -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SCRIPTS/PREIN @@ -28,5 +29,12 @@ dr-xr-xr-x 3 0 0 0 2017-01-05 00:00:00 INFO -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SCRIPTS/PREUNPROG -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SCRIPTS/POSTUNPROG -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/SCRIPTS/VERIFYSCRIPTPROG +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/PACKAGER +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/URL +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/EPOCH +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/LICENSE +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/REQUIRES +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/OBSOLETES +-r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/PROVIDES -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 INFO/CHANGELOG -r--r--r-- 1 0 0 0 2017-01-05 00:00:00 CONTENTS.cpio From 95f2f1435790d372d105f25b70ec765e073d87d3 Mon Sep 17 00:00:00 2001 From: Mooffie Date: Wed, 8 Mar 2017 17:47:24 +0200 Subject: [PATCH 2/4] extfs: rpm: use printf instead of echo, to calculate DESCRIPTION length. Out test input intentionally contains weird characters in the DESCRIPTION field (see the file 'test.spec'[1]). It turns out that backslash sequences, as in our DESCRIPTION field, are processed by the 'echo' command in some shells (i.e., Dash). In other words, 'echo' can't be used to print arbitrary data verbatim. Indeed, the standard says[2] that "if any of the operands contain a character, the results are implementation-defined". You can see the problem by running: $ echo "one \\a two" under both Bash and Dash: you'll get different results. The solution: we replace 'echo' with 'printf'. [1] https://midnight-commander.org/browser/tests/src/vfs/extfs/helpers-list/misc/rpm/test.spec#L34 [2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html Signed-off-by: Mooffie --- src/vfs/extfs/helpers/rpm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vfs/extfs/helpers/rpm b/src/vfs/extfs/helpers/rpm index de3c605d6..c41732d87 100755 --- a/src/vfs/extfs/helpers/rpm +++ b/src/vfs/extfs/helpers/rpm @@ -224,7 +224,7 @@ mcrpmfs_list () DATE=`mcrpmfs_getRawOneTag "%{BUILDTIME:date}\n" | cut -c 5-11,21-24` PAYLOAD=`mcrpmfs_getRawOneTag "%{PAYLOADFORMAT}\n" | sed s/ustar/tar/` - HEADERSIZE=`echo "$DESC" | wc -c` + HEADERSIZE=`printf '%s\n' "$DESC" | wc -c` # 'echo' can't be used for arbitrary data (see commit message). printf '%s %s %s HEADER\n' "${FILEPREF}" "${HEADERSIZE}" "${DATE}" echo "-r-xr-xr-x 1 root root 39 $DATE INSTALL" case "${rpm_filename}" in From 25aa5db3fd956e99ccb2074a21b7ef650eacc7e8 Mon Sep 17 00:00:00 2001 From: Mooffie Date: Mon, 6 Mar 2017 19:16:24 +0200 Subject: [PATCH 3/4] extfs: rpm: wrap variable in quotes. Our goal is to replace the 'echo' with 'printf' on this line, for the reason described in the previous commit. But before we do this we need to wrap one variable in quotes. This preliminary step does not affect the output of the helper. As for using "tr \n ' '": this mimics the current behavior (when using no quotes around the variable, newlines are converted to spaces by the shell; now that we do have quotes we need to do this conversion ourselves). An alternative is to tweak the sed script to be smarter, but it turns out it's not a simple task. Signed-off-by: Mooffie --- src/vfs/extfs/helpers/rpm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vfs/extfs/helpers/rpm b/src/vfs/extfs/helpers/rpm index c41732d87..39f53c929 100755 --- a/src/vfs/extfs/helpers/rpm +++ b/src/vfs/extfs/helpers/rpm @@ -111,7 +111,8 @@ mcrpmfs_getAllNeededTags() "|PROVIDES=%{PROVIDES} %{PROVIDEFLAGS:depflags} %{PROVIDEVERSION}"\ ${tag_CONFLICTS}\ "|PACKAGER=%{PACKAGER}" \ - "${rpm_filename}" + "${rpm_filename}" \ + | tr '\n' ' ' # The newlines in DESCRIPTION mess with the sed script in mcrpmfs_getOneTag(). } mcrpmfs_getRawOneTag() @@ -121,7 +122,7 @@ mcrpmfs_getRawOneTag() mcrpmfs_getOneTag() { - echo $AllTAGS | $SED "s/.*|${1}=//" | cut -d '|' -f 1 + echo "$AllTAGS" | $SED "s/.*|${1}=//" | cut -d '|' -f 1 } mcrpmfs_printOneMetaInfo() From a6cd7c9f45d42dff0daa97937abe5e50489affb0 Mon Sep 17 00:00:00 2001 From: Mooffie Date: Wed, 8 Mar 2017 18:56:05 +0200 Subject: [PATCH 4/4] extfs: rpm: use printf instead of echo, when retrieving fields. We switch to using 'echo' instead of 'printf', for the reason described in a previous commit. This time, however, we don't do this in order to preserve the value of the DESCRIPTION field (because we retrieve it using some other command). We do this for two reasons: * As chance would have it, we have the string '\c' in our DESCRIPTION. It turns out that Dash's echo interprets '\c' to mean the end of the data[1], so fields stored in $AllTAGS after DESCRIPTION aren't seen by our sed script (resulting in the helper not reporting a few file entries). * We also have '\n' in DESCRIPTION. This would translate, by echo, into newline, failing the naive sed script. [1] See "\c as in SYSV echo - abort all processing..." in the source code of Dash: https://github.com/gioele/dash/blob/master/src/bltin/printf.c Signed-off-by: Mooffie --- src/vfs/extfs/helpers/rpm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vfs/extfs/helpers/rpm b/src/vfs/extfs/helpers/rpm index 39f53c929..7cb2a1b0c 100755 --- a/src/vfs/extfs/helpers/rpm +++ b/src/vfs/extfs/helpers/rpm @@ -122,7 +122,8 @@ mcrpmfs_getRawOneTag() mcrpmfs_getOneTag() { - echo "$AllTAGS" | $SED "s/.*|${1}=//" | cut -d '|' -f 1 + # 'echo' can't be used for arbitrary data (see commit message). + printf "%s" "$AllTAGS" | $SED "s/.*|${1}=//" | cut -d '|' -f 1 } mcrpmfs_printOneMetaInfo()