From 5ea412e4de1bf18a6ceb960a66feb70f018b8e65 Mon Sep 17 00:00:00 2001 From: LiuHao Date: Mon, 6 Jan 2020 10:32:09 +0800 Subject: [PATCH] check invalid argument Signed-off-by: LiuHao --- src/types/current.c | 3 +++ src/types/types.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/types/current.c b/src/types/current.c index 1da0d73..673aefd 100644 --- a/src/types/current.c +++ b/src/types/current.c @@ -124,6 +124,9 @@ static int do_parse_ipnet(const char *cidr_str, const char *ip_str, uint8_t **ip ERROR("Parse cidr failed: %s", *err != NULL ? *err : ""); return -1; } + if (ip_str == NULL) { + return 0; + } ret = parse_ip_from_str(ip_str, ip, ip_len, err); if (ret != 0) { ERROR("Parse ip failed: %s", *err != NULL ? *err : ""); diff --git a/src/types/types.c b/src/types/types.c index 9aa581f..55d0a0b 100644 --- a/src/types/types.c +++ b/src/types/types.c @@ -645,6 +645,10 @@ static int do_parse_ipv6_from_str(const char *addr, struct in6_addr *ipv6, uint8 { int nret = 0; + if (addr == NULL) { + ERROR("Empty address"); + return -1; + } nret = inet_pton(AF_INET6, addr, ipv6); if (nret < 0) { nret = asprintf(err, "ipv6 inet_pton %s", strerror(errno)); @@ -674,6 +678,10 @@ int parse_ip_from_str(const char *addr, uint8_t **ips, size_t *len, char **err) struct in6_addr ipv6; int ret = -1; + if (addr == NULL) { + ERROR("Empty address"); + return -1; + } nret = inet_pton(AF_INET, addr, &ipv4); if (nret < 0) { nret = asprintf(err, "ipv4 inet_pton %s", strerror(errno)); -- GitLab