Comment 0 for bug 1547060

Revision history for this message
stsp (stsp-0) wrote :

tgt-1:1.0.62-1ubuntu2

# ./tgtd -d 1
-d argument value '1' invalid
Try `tgtd --help' for more information.

The following change should fix the problem:

--- util.h.old 2015-12-02 03:27:15.000000000 +0300
+++ util.h 2016-02-18 18:04:08.749932076 +0300
@@ -148,7 +148,7 @@
        unsigned long long ull_val; \
        ull_val = strtoull(str, &ptr, 0); \
        val = (typeof(val)) ull_val; \
- if (errno || ptr == str) \
+ if (ull_val == ULONG_MAX || ptr == str) \
                ret = EINVAL; \
        else if (val != ull_val) \
                ret = ERANGE; \

Here, the errno is checked incorrectly: you can't check
errno unless the returned value allows you to. In case
of strtoull(), errno should be checked only if ULONG_MAX is
returned.
I however can't test the fix properly because when compiled
from source, the bug doesn't happen. The value of errno is
unspecified, and it just happens to be 0 when I compile from
sources.