]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
utils: fix error path for nft_strtoi
authorArturo Borrero <arturo.borrero.glez@gmail.com>
Mon, 19 Aug 2013 12:37:30 +0000 (14:37 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 20 Aug 2013 11:08:51 +0000 (13:08 +0200)
If the return of nft_get_value() is not evaluated, we don't know if
the parsed value is between the limits of its type.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/utils.c

index 848eba94bfdbf4e424f9133491964892edd0f1e7..9a0bcfec1fc1d615ed3970104da09abfd4788eb7 100644 (file)
@@ -103,6 +103,7 @@ int nft_get_value(enum nft_type type, void *val, void *out)
 
 int nft_strtoi(const char *string, int base, void *out, enum nft_type type)
 {
+       int ret;
        int64_t sval = 0;
        uint64_t uval = -1;
        char *endptr;
@@ -113,14 +114,14 @@ int nft_strtoi(const char *string, int base, void *out, enum nft_type type)
        case NFT_TYPE_U32:
        case NFT_TYPE_U64:
                uval = strtoll(string, &endptr, base);
-               nft_get_value(type, &uval, out);
+               ret = nft_get_value(type, &uval, out);
                break;
        case NFT_TYPE_S8:
        case NFT_TYPE_S16:
        case NFT_TYPE_S32:
        case NFT_TYPE_S64:
                sval = strtoull(string, &endptr, base);
-               nft_get_value(type, &sval, out);
+               ret = nft_get_value(type, &sval, out);
                break;
        default:
                errno = EINVAL;
@@ -132,7 +133,7 @@ int nft_strtoi(const char *string, int base, void *out, enum nft_type type)
                return -1;
        }
 
-       return 0;
+       return ret;
 }
 
 const char *nft_verdict2str(uint32_t verdict)