From 6712de30a401adc814e7471cfbdadc2fe90e442d Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Sat, 27 Mar 2021 08:09:09 +0100 Subject: [PATCH] confile: make string calculations in get_network_config_ops() more obvious Signed-off-by: Christian Brauner --- src/lxc/confile.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 2047879f5..48df7e3a9 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -4708,7 +4708,7 @@ 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); @@ -4716,15 +4716,15 @@ static struct lxc_config_t *get_network_config_ops(const char *key, return log_error_errno(NULL, ENOMEM, "Failed to duplicate string \"%s\"", key); /* lxc.net. */ - 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'; @@ -4754,7 +4754,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); -- 2.47.3