diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-11-18 16:48:19 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-11-21 22:47:47 +0100 |
commit | fd18634de4d84eba2422908948c27ec6c5bf4cf5 (patch) | |
tree | 612b668eab1c27b2da78c0308f4caa93ad4ba268 | |
parent | fdedbe2676b4f9142246c6ac1f42181174ab22f0 (diff) |
basic: make sure in_addr_from_string() can take NULL arguments
This way, we can use it for validating IP address strings.
-rw-r--r-- | src/basic/in-addr-util.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index d6c979acef..3b06cb00ad 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -283,15 +283,14 @@ fallback: } int in_addr_from_string(int family, const char *s, union in_addr_union *ret) { - + union in_addr_union buffer; assert(s); - assert(ret); if (!IN_SET(family, AF_INET, AF_INET6)) return -EAFNOSUPPORT; errno = 0; - if (inet_pton(family, s, ret) <= 0) + if (inet_pton(family, s, ret ?: &buffer) <= 0) return errno > 0 ? -errno : -EINVAL; return 0; @@ -301,18 +300,18 @@ int in_addr_from_string_auto(const char *s, int *family, union in_addr_union *re int r; assert(s); - assert(family); - assert(ret); r = in_addr_from_string(AF_INET, s, ret); if (r >= 0) { - *family = AF_INET; + if (family) + *family = AF_INET; return 0; } r = in_addr_from_string(AF_INET6, s, ret); if (r >= 0) { - *family = AF_INET6; + if (family) + *family = AF_INET6; return 0; } |