attach: convert to strnprintf()

parent 76ae4ba2
...@@ -116,8 +116,8 @@ static pid_t pidfd_get_pid(int dfd_init_pid, int pidfd) ...@@ -116,8 +116,8 @@ static pid_t pidfd_get_pid(int dfd_init_pid, int pidfd)
if (dfd_init_pid < 0 || pidfd < 0) if (dfd_init_pid < 0 || pidfd < 0)
return ret_errno(EBADF); return ret_errno(EBADF);
ret = snprintf(path + STRLITERALLEN("fdinfo/"), INTTYPE_TO_STRLEN(int), "%d", pidfd); ret = strnprintf(path + STRLITERALLEN("fdinfo/"), INTTYPE_TO_STRLEN(int), "%d", pidfd);
if (ret < 0 || ret > (size_t)INTTYPE_TO_STRLEN(int)) if (ret < 0)
return ret_errno(EIO); return ret_errno(EIO);
f = fdopen_at(dfd_init_pid, path, "re", PROTECT_OPEN, PROTECT_LOOKUP_BENEATH); 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, ...@@ -403,8 +403,8 @@ static int get_attach_context(struct attach_context *ctx,
if (ctx->init_pid < 0) if (ctx->init_pid < 0)
return log_error(-1, "Failed to get init pid"); return log_error(-1, "Failed to get init pid");
ret = snprintf(path, sizeof(path), "/proc/%d", ctx->init_pid); ret = strnprintf(path, sizeof(path), "/proc/%d", ctx->init_pid);
if (ret < 0 || ret >= sizeof(path)) if (ret < 0)
return ret_errno(EIO); return ret_errno(EIO);
ctx->dfd_init_pid = open_at(-EBADF, path, ctx->dfd_init_pid = open_at(-EBADF, path,
...@@ -947,8 +947,8 @@ static char *lxc_attach_getpwshell(uid_t uid) ...@@ -947,8 +947,8 @@ static char *lxc_attach_getpwshell(uid_t uid)
} }
/* Finish argument list. */ /* Finish argument list. */
ret = snprintf(uid_buf, sizeof(uid_buf), "%ld", (long)uid); ret = strnprintf(uid_buf, sizeof(uid_buf), "%ld", (long)uid);
if (ret <= 0 || ret >= sizeof(uid_buf)) if (ret <= 0)
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* Try to run getent program. */ /* Try to run getent program. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment