build/i18n-scan.pl: avoid a possible endless loop
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 2 Apr 2012 22:50:40 +0000 (22:50 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 2 Apr 2012 22:50:40 +0000 (22:50 +0000)
Issuing './build/i18n-scan.pl libs/core/' leads to this
endless loop with some perl implementations:

<...>
Use of uninitialized value in concatenation (.) or string at../build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
Use of uninitialized value in concatenation (.) or string at ./build/i18n-scan.pl line 69.
substr outside of string at ./build/i18n-scan.pl line 69.
<...>

Experienced with this perl version:
"This is perl, v5.8.8 built for i386-linux"

Fix it by undefining the 'sub' variable if it is an
empty string.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
build/i18n-scan.pl

index 8807384..3f73271 100755 (executable)
@@ -64,6 +64,10 @@ if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' ')' |" )
                                        {
                                                ( $sub, $code ) = extract_delimited($code, q{'"}, q{\s*(?:\.\.\s*)?});
 
+                                               if( length($sub) < 1 ) {
+                                                       undef $sub;
+                                               }
+
                                                if( defined $sub )
                                                {
                                                        $res .= substr $sub, 1, length($sub) - 2;