Bug 1915 - Ash -ne test does not fail correctly
Summary: Ash -ne test does not fail correctly
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: unspecified
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-02 21:51 UTC by Jake Magee
Modified: 2010-06-02 23:47 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jake Magee 2010-06-02 21:51:32 UTC
OVERVIEW:
When using the "-ne" test with an empty variable and a number, the test fails (reports that "" is equal to "0").

On an Ubuntu system running Bash, the following error is produced:
"-bash: [: : integer expression expected"

STEPS TO REPRODUCE:
The following code is an example:
#!/bin/sh
test=""
if [ "$test" -ne "0" ]
then
    echo "An error or this should be printed out."
fi

ACTUAL RESULTS:
nothing (the -ne test fails with "" equal to "0")

EXPECTED RESULTS:
an Ash error like "[: : integer expression expected"

PLATFORM:
Using BusyBox 1.11.2 on a PowerPC Linux (OpenWRT 8.01) system.
Comment 1 Denys Vlasenko 2010-06-02 23:46:54 UTC
Fix:


--- busybox.3/coreutils/test.c  2010-05-31 02:14:36.000000000 +0200
+++ busybox.4/coreutils/test.c  2010-06-03 01:45:59.000000000 +0200
@@ -393,7 +393,7 @@ static number_t getn(const char *s)
        if (errno != 0)
                syntax(s, "out of range");

-       if (*(skip_whitespace(p)))
+       if (p == s || *(skip_whitespace(p)))
                syntax(s, "bad number");

        return r;


I am committing it to git.