From: Christian Brauner Date: Thu, 11 Feb 2021 09:16:34 +0000 (+0100) Subject: attach: convert to strnprintf() X-Git-Tag: lxc-5.0.0~292^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f51c7eb43eab61086d02c1c67ed11c28f2d9585c;p=thirdparty%2Flxc.git attach: convert to strnprintf() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index f705f552b..afdfa610c 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -116,8 +116,8 @@ static pid_t pidfd_get_pid(int dfd_init_pid, int pidfd) if (dfd_init_pid < 0 || pidfd < 0) return ret_errno(EBADF); - ret = snprintf(path + STRLITERALLEN("fdinfo/"), INTTYPE_TO_STRLEN(int), "%d", pidfd); - if (ret < 0 || ret > (size_t)INTTYPE_TO_STRLEN(int)) + ret = strnprintf(path + STRLITERALLEN("fdinfo/"), INTTYPE_TO_STRLEN(int), "%d", pidfd); + if (ret < 0) return ret_errno(EIO); f = fdopen_at(dfd_init_pid, path, "re", PROTECT_OPEN, PROTECT_LOOKUP_BENEATH); @@ -403,8 +403,8 @@ static int get_attach_context(struct attach_context *ctx, if (ctx->init_pid < 0) return log_error(-1, "Failed to get init pid"); - ret = snprintf(path, sizeof(path), "/proc/%d", ctx->init_pid); - if (ret < 0 || ret >= sizeof(path)) + ret = strnprintf(path, sizeof(path), "/proc/%d", ctx->init_pid); + if (ret < 0) return ret_errno(EIO); ctx->dfd_init_pid = open_at(-EBADF, path, @@ -947,8 +947,8 @@ static char *lxc_attach_getpwshell(uid_t uid) } /* Finish argument list. */ - ret = snprintf(uid_buf, sizeof(uid_buf), "%ld", (long)uid); - if (ret <= 0 || ret >= sizeof(uid_buf)) + ret = strnprintf(uid_buf, sizeof(uid_buf), "%ld", (long)uid); + if (ret <= 0) _exit(EXIT_FAILURE); /* Try to run getent program. */