]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: convert to strnprintf()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 11 Feb 2021 09:16:34 +0000 (10:16 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 11 Feb 2021 09:16:34 +0000 (10:16 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c

index f705f552b5ad00606343dc8d4b2300333e7349a9..afdfa610ce8dfe473e78cb2533e3252781d91ca1 100644 (file)
@@ -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. */