Commit 4c19bbdc authored by David Howells's avatar David Howells

afs: Always build address lists using the helper functions

Make the address list string parser use the helper functions for adding
addresses to an address list so that they end up appropriately sorted.
This will better handles overruns and make them easier to compare.

It also reduces the number of places that addresses are handled, making it
easier to fix the handling.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 68eb64c3
...@@ -116,8 +116,10 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -116,8 +116,10 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
/* Extract the addresses */ /* Extract the addresses */
p = text; p = text;
do { do {
struct sockaddr_rxrpc *srx = &alist->addrs[alist->nr_addrs];
const char *q, *stop; const char *q, *stop;
unsigned int xport = port;
__be32 x[4];
int family;
if (*p == delim) { if (*p == delim) {
p++; p++;
...@@ -133,19 +135,12 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -133,19 +135,12 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
break; break;
} }
if (in4_pton(p, q - p, if (in4_pton(p, q - p, (u8 *)&x[0], -1, &stop))
(u8 *)&srx->transport.sin6.sin6_addr.s6_addr32[3], family = AF_INET;
-1, &stop)) { else if (in6_pton(p, q - p, (u8 *)x, -1, &stop))
srx->transport.sin6.sin6_addr.s6_addr32[0] = 0; family = AF_INET6;
srx->transport.sin6.sin6_addr.s6_addr32[1] = 0; else
srx->transport.sin6.sin6_addr.s6_addr32[2] = htonl(0xffff);
} else if (in6_pton(p, q - p,
srx->transport.sin6.sin6_addr.s6_addr,
-1, &stop)) {
/* Nothing to do */
} else {
goto bad_address; goto bad_address;
}
if (stop != q) if (stop != q)
goto bad_address; goto bad_address;
...@@ -157,7 +152,7 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -157,7 +152,7 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
if (p < end) { if (p < end) {
if (*p == '+') { if (*p == '+') {
/* Port number specification "+1234" */ /* Port number specification "+1234" */
unsigned int xport = 0; xport = 0;
p++; p++;
if (p >= end || !isdigit(*p)) if (p >= end || !isdigit(*p))
goto bad_address; goto bad_address;
...@@ -168,7 +163,6 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -168,7 +163,6 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
goto bad_address; goto bad_address;
p++; p++;
} while (p < end && isdigit(*p)); } while (p < end && isdigit(*p));
srx->transport.sin6.sin6_port = htons(xport);
} else if (*p == delim) { } else if (*p == delim) {
p++; p++;
} else { } else {
...@@ -176,8 +170,12 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -176,8 +170,12 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
} }
} }
alist->nr_addrs++; if (family == AF_INET)
} while (p < end && alist->nr_addrs < alist->max_addrs); afs_merge_fs_addr4(alist, x[0], xport);
else
afs_merge_fs_addr6(alist, x, xport);
} while (p < end);
_leave(" = [nr %u]", alist->nr_addrs); _leave(" = [nr %u]", alist->nr_addrs);
return alist; return alist;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment