Skip to content

Commit

Permalink
confile: make string calculations in get_network_config_ops() more ob…
Browse files Browse the repository at this point in the history
…vious

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Mar 27, 2021
1 parent ced5587 commit 6a52a51
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lxc/confile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5171,23 +5171,23 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
char *idx_start, *idx_end;

/* check that this is a sensible network key */
if (!strnequal("lxc.net.", key, 8))
if (!strnequal("lxc.net.", key, STRLITERALLEN("lxc.net.")))
return log_error_errno(NULL, EINVAL, "Invalid network configuration key \"%s\"", key);

copy = strdup(key);
if (!copy)
return log_error_errno(NULL, ENOMEM, "Failed to duplicate string \"%s\"", key);

/* lxc.net.<n> */
if (!isdigit(*(key + 8)))
if (!isdigit(*(key + STRLITERALLEN("lxc.net."))))
return log_error_errno(NULL, EINVAL, "Failed to detect digit in string \"%s\"", key + 8);

/* beginning of index string */
idx_start = (copy + 7);
idx_start = copy + (STRLITERALLEN("lxc.net.") - 1);
*idx_start = '\0';

/* end of index string */
idx_end = strchr((copy + 8), '.');
idx_end = strchr((copy + STRLITERALLEN("lxc.net.")), '.');
if (idx_end)
*idx_end = '\0';

Expand Down Expand Up @@ -5217,7 +5217,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
if (strlen(idx_end + 1) == 0)
return log_error_errno(NULL, EINVAL, "No subkey in network configuration key \"%s\"", key);

memmove(copy + 8, idx_end + 1, strlen(idx_end + 1));
memmove(copy + STRLITERALLEN("lxc.net."), idx_end + 1, strlen(idx_end + 1));
copy[strlen(key) - (numstrlen + 1)] = '\0';

config = lxc_get_config(copy);
Expand Down

0 comments on commit 6a52a51

Please sign in to comment.