Skip to content

Commit

Permalink
s390/qeth: clean up string ops in qeth_l3_parse_ipatoe()
Browse files Browse the repository at this point in the history
Indicate the max number of to-be-parsed characters, and avoid copying
the address sub-string.

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Julian Wiedmann authored and David S. Miller committed Sep 23, 2020
1 parent d6e6426 commit bcdfdf0
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions drivers/s390/net/qeth_l3_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,22 @@ static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
u8 *addr, int *mask_bits)
{
const char *start, *end;
char *tmp;
char buffer[40] = {0, };
const char *start;
char *sep, *tmp;
int rc;

start = buf;
/* get address string */
end = strchr(start, '/');
if (!end || (end - start >= 40)) {
/* Expected input pattern: %addr/%mask */
sep = strnchr(buf, 40, '/');
if (!sep)
return -EINVAL;
}
strncpy(buffer, start, end - start);
if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
return -EINVAL;
}
start = end + 1;

/* Terminate the %addr sub-string, and parse it: */
*sep = '\0';
rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
if (rc)
return rc;

start = sep + 1;
*mask_bits = simple_strtoul(start, &tmp, 10);
if (!strlen(start) ||
(tmp == start) ||
Expand Down

0 comments on commit bcdfdf0

Please sign in to comment.