commit:     4b27824ee27013c672f75bce2066c950a71280d2
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Aug  5 19:39:21 2023 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sat Aug  5 20:08:11 2023 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=4b27824e

resolve_dirfd_path: use separate buffer for readlink

Fixes a compile warning:
```
warning: passing argument 2 to 'restrict'-qualified parameter aliases with 
argument 1 [-Wrestrict]
```

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 libsandbox/libsandbox.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c
index 4edcf60..6a7368c 100644
--- a/libsandbox/libsandbox.c
+++ b/libsandbox/libsandbox.c
@@ -132,24 +132,25 @@ int resolve_dirfd_path(int dirfd, const char *path, char 
*resolved_path,
 
        save_errno();
 
+       char fd_path[SB_PATH_MAX];
        size_t at_len = resolved_path_len - 1 - 1 - (path ? strlen(path) : 0);
        if (trace_pid) {
-               sprintf(resolved_path, "/proc/%i/fd/%i", trace_pid, dirfd);
+               sprintf(fd_path, "/proc/%i/fd/%i", trace_pid, dirfd);
        } else {
                /* If /proc was mounted by a process in a different pid 
namespace,
                 * getpid cannot be used to create a valid /proc/<pid> path. 
Instead
                 * use sb_get_fd_dir() which works in any case.
                 */
-               sprintf(resolved_path, "%s/%i", sb_get_fd_dir(), dirfd);
+               sprintf(fd_path, "%s/%i", sb_get_fd_dir(), dirfd);
        }
-       ssize_t ret = readlink(resolved_path, resolved_path, at_len);
+       ssize_t ret = readlink(fd_path, resolved_path, at_len);
        if (ret == -1) {
                /* see comments at end of check_syscall() */
                if (errno_is_too_long()) {
                        restore_errno();
                        return 2;
                }
-               sb_debug_dyn("AT_FD LOOKUP fail: %s: %s\n", resolved_path, 
strerror(errno));
+               sb_debug_dyn("AT_FD LOOKUP fail: %s: %s\n", fd_path, 
strerror(errno));
                /* If the fd isn't found, some guys (glibc) expect errno */
                if (errno == ENOENT)
                        errno = EBADF;

Reply via email to