summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-08-22 16:23:54 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-08-22 16:23:54 +0200
commit5b55659baebd314a00e0219e65e356a9acdbc40a (patch)
tree3efd24ebb0879166ac069247ce44098af4334a49 /lib-src
parente8e78809ba701eb8031120697bb9b3383473b86c (diff)
downloademacs-5b55659baebd314a00e0219e65e356a9acdbc40a.tar.gz
Avoid using %n in emacsclient
* lib-src/emacsclient.c (local_sockname): Avoid using %n (bug#50155).
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 8346524a3eb..018e81e4222 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1401,10 +1401,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen,
/* Put the full address name into the buffer, since the caller might
need it for diagnostics. But don't overrun the buffer. */
uintmax_t uidmax = uid;
- int emacsdirlen;
int suffixlen = snprintf (sockname + tmpdirlen, socknamesize - tmpdirlen,
- "/emacs%"PRIuMAX"%n/%s", uidmax, &emacsdirlen,
- server_name);
+ "/emacs%"PRIuMAX"/%s", uidmax, server_name);
if (! (0 <= suffixlen && suffixlen < socknamesize - tmpdirlen))
return ENAMETOOLONG;
@@ -1412,7 +1410,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen,
this user's directory and does not let others write to it; this
fends off some symlink attacks. To avoid races, keep the parent
directory open while checking. */
- char *emacsdirend = sockname + tmpdirlen + emacsdirlen;
+ char *emacsdirend = sockname + tmpdirlen + suffixlen -
+ strlen(server_name) - 1;
*emacsdirend = '\0';
int dir = openat (AT_FDCWD, sockname,
O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);