From: Christian Brauner Date: Sun, 19 Aug 2018 17:37:49 +0000 (+0200) Subject: cmd: simplify lxc-usernsexec X-Git-Tag: lxc-3.1.0~145^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ff0284480da1d1601c3980afefd307715786198;p=thirdparty%2Flxc.git cmd: simplify lxc-usernsexec Calculate length only once. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c index fa1b6a233..a2c518005 100644 --- a/src/lxc/cmd/lxc_usernsexec.c +++ b/src/lxc/cmd/lxc_usernsexec.c @@ -194,8 +194,9 @@ static int parse_map(char *map) * only use the first one for each of uid and gid, because otherwise we're not * sure which entries the user wanted. */ -static int read_default_map(char *fnam, int which, char *username) +static int read_default_map(char *fnam, int which, char *user) { + size_t len; char *p1, *p2; FILE *fin; struct id_map *newmap; @@ -207,10 +208,9 @@ static int read_default_map(char *fnam, int which, char *username) if (!fin) return -1; + len = strlen(user); while (getline(&line, &sz, fin) != -1) { - if (sz <= strlen(username) || - strncmp(line, username, strlen(username)) != 0 || - line[strlen(username)] != ':') + if (sz <= len || strncmp(line, user, len) != 0 || line[len] != ':') continue; p1 = strchr(line, ':');