All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH xtables-addons] build: fix configure compatiblity with POSIX shells
@ 2016-04-01 20:35 Matthias Schiffer
  2016-04-03 10:11 ` Jan Engelhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Matthias Schiffer @ 2016-04-01 20:35 UTC (permalink / raw)
  To: jengelh; +Cc: netfilter-devel

The kernel version detection code uses some bashisms, which makes the build
fail on Debian systems where /bin/sh links to dash. Replace with POSIX-
conforming commands at the cost of requiring awk.
---
 configure.ac | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/configure.ac b/configure.ac
index 82a1355..735c090 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,21 +44,15 @@ regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \
 
 if test -n "$kbuilddir"; then
 	AC_MSG_CHECKING([kernel version that we will build against])
-	krel="$(make -sC "$kbuilddir" M=$PWD kernelrelease)";
-	kmajor="${krel%%[[^0-9]]*}";
-	kmajor="$(($kmajor+0))";
-	krel="${krel:${#kmajor}}";
-	krel="${krel#.}";
-	kminor="${krel%%[[^0-9]]*}";
-	kminor="$(($kminor+0))";
-	krel="${krel:${#kminor}}";
-	krel="${krel#.}";
-	kmicro="${krel%%[[^0-9]]*}";
-	kmicro="$(($kmicro+0))";
-	krel="${krel:${#kmicro}}";
-	krel="${krel#.}";
-	kstable="${krel%%[[^0-9]]*}";
-	kstable="$(($kstable+0))";
+	krel="$(make -sC "$kbuilddir" M=$PWD kernelrelease | $AWK -v 'FS=[[^0-9.]]' '{print $1; exit}')";
+	save_IFS=$IFS;
+	IFS='.';
+	set x $krel;
+	kmajor="$(($2+0))";
+	kminor="$(($3+0))";
+	kmicro="$(($4+0))";
+	kstable="$(($5+0))";
+	IFS=$save_IFS;
 	if test -z "$kmajor" -o -z "$kminor" -o -z "$kmicro"; then
 		echo "WARNING: Version detection did not succeed. Continue at own luck.";
 	else
-- 
2.8.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH xtables-addons] build: fix configure compatiblity with POSIX shells
  2016-04-01 20:35 [PATCH xtables-addons] build: fix configure compatiblity with POSIX shells Matthias Schiffer
@ 2016-04-03 10:11 ` Jan Engelhardt
  2016-04-03 11:57   ` Matthias Schiffer
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Engelhardt @ 2016-04-03 10:11 UTC (permalink / raw)
  To: Matthias Schiffer; +Cc: netfilter-devel

On Friday 2016-04-01 22:35, Matthias Schiffer wrote:

>The kernel version detection code uses some bashisms, which makes the build
>fail on Debian systems where /bin/sh links to dash. Replace with POSIX-
>conforming commands at the cost of requiring awk.
>+	krel="$(make -sC "$kbuilddir" M=$PWD kernelrelease | $AWK -v 'FS=[[^0-9.]]' '{print $1; exit}')";
>+	save_IFS=$IFS;
>+	IFS='.';
>+	set x $krel;
>+	kmajor="$(($2+0))";
>+	kminor="$(($3+0))";
>+	kmicro="$(($4+0))";
>+	kstable="$(($5+0))";
>+	IFS=$save_IFS;
> 	if test -z "$kmajor" -o -z "$kminor" -o -z "$kmicro"; then

To test its resilience against silly krel strings (not exactly unheard of),
let's pretend that

	krel="4x.6.0"

The previous code would conclude (albeit with a silly broken-up version like
4.0.6.0 or 0.0.0.0). However, your change makes the script totally falls over:

checking kernel version that we will build against... ./configure: line
11957: 4x: value too great for base (error toke
n is "4x")
./configure: line 8: printf %s\n: command not found
./configure: line 14: AMDEPBACKSLASH: command not found
./configure: line 15: AMDEP_FALSE: command not found
./configure: line 16: AMDEP_TRUE: command not found
./configure: line 17: AMTAR: command not found
[...]

(and who knows what other commands - rm? - it tries to execute by sheer
chance).
Is it possible to harden the dash-compatible variant?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH xtables-addons] build: fix configure compatiblity with POSIX shells
  2016-04-03 10:11 ` Jan Engelhardt
@ 2016-04-03 11:57   ` Matthias Schiffer
  2016-04-03 16:01     ` Jan Engelhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Matthias Schiffer @ 2016-04-03 11:57 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: netfilter-devel


[-- Attachment #1.1: Type: text/plain, Size: 2286 bytes --]

On 04/03/2016 12:11 PM, Jan Engelhardt wrote:
> On Friday 2016-04-01 22:35, Matthias Schiffer wrote:
> 
>> The kernel version detection code uses some bashisms, which makes the build
>> fail on Debian systems where /bin/sh links to dash. Replace with POSIX-
>> conforming commands at the cost of requiring awk.
>> +	krel="$(make -sC "$kbuilddir" M=$PWD kernelrelease | $AWK -v 'FS=[[^0-9.]]' '{print $1; exit}')";
>> +	save_IFS=$IFS;
>> +	IFS='.';
>> +	set x $krel;
>> +	kmajor="$(($2+0))";
>> +	kminorb="$(($3+0))";
>> +	kmicro="$(($4+0))";
>> +	kstable="$(($5+0))";
>> +	IFS=$save_IFS;
>> 	if test -z "$kmajor" -o -z "$kminor" -o -z "$kmicro"; then
> 
> To test its resilience against silly krel strings (not exactly unheard of),
> let's pretend that
> 
> 	krel="4x.6.0"
> 
> The previous code would conclude (albeit with a silly broken-up version like
> 4.0.6.0 or 0.0.0.0). However, your change makes the script totally falls over:
> 
> checking kernel version that we will build against... ./configure: line
> 11957: 4x: value too great for base (error toke
> n is "4x")
> ./configure: line 8: printf %s\n: command not found
> ./configure: line 14: AMDEPBACKSLASH: command not found
> ./configure: line 15: AMDEP_FALSE: command not found
> ./configure: line 16: AMDEP_TRUE: command not found
> ./configure: line 17: AMTAR: command not found
> [...]
> 
> (and who knows what other commands - rm? - it tries to execute by sheer
> chance).
> Is it possible to harden the dash-compatible variant?
> 

Weird, what version/variant of awk are you using (or were you just changing
the value of krel in an artificial test and dropped the awk call
altogether)? krel should be cut off at the first character not in the set
[0-9.], so krel would be "4" and version 4.0.0.0 should result.

If found out though that configure really doesn't like failures while IFS
is modified, as it sets up a cleanup trap that will break completely in
this case (resulting in the tons of "command not found").

I'll send a v2 which resets IFS to its old value directly after the set
line, so even on systems with broken awk (which should not exist), the
script will just fail with "4x: value too great for base" or similar, and
nothing worse.

Matthias


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH xtables-addons] build: fix configure compatiblity with POSIX shells
  2016-04-03 11:57   ` Matthias Schiffer
@ 2016-04-03 16:01     ` Jan Engelhardt
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Engelhardt @ 2016-04-03 16:01 UTC (permalink / raw)
  To: Matthias Schiffer; +Cc: netfilter-devel


On Sunday 2016-04-03 13:57, Matthias Schiffer wrote:
>> To test its resilience against silly krel strings (not exactly unheard of),
>> let's pretend that
>> 
>> 	krel="4x.6.0"
>> 
>> checking kernel version that we will build against... ./configure: line
>> 11957: 4x: value too great for base (error toke
>> n is "4x")
>> ./configure: line 8: printf %s\n: command not found
>
>Weird, what version/variant of awk are you using (or were you just changing
>the value of krel in an artificial test and dropped the awk call
>altogether)? krel should be cut off at the first character not in the set
>[0-9.], so krel would be "4" and version 4.0.0.0 should result.

Aha; yes, I had dropped awk altogether.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-03 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-01 20:35 [PATCH xtables-addons] build: fix configure compatiblity with POSIX shells Matthias Schiffer
2016-04-03 10:11 ` Jan Engelhardt
2016-04-03 11:57   ` Matthias Schiffer
2016-04-03 16:01     ` Jan Engelhardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.