aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2018-11-21 11:35:44 -0800
committerPaul Eggert2018-11-21 11:36:57 -0800
commit8f49cb00d06e06c2db67305433e743e706645bb2 (patch)
tree306fdd97979dc375c64922c277937e12800836c1 /lib-src
parentc0870736ff4546a28afd7ccc1a2f254c7ef6743e (diff)
downloademacs-8f49cb00d06e06c2db67305433e743e706645bb2.tar.gz
emacs-8f49cb00d06e06c2db67305433e743e706645bb2.zip
emacsclient: take more care with int width
* lib-src/emacsclient.c: Include inttypes.h, stddef.h. (emacs_pid, main): Don’t assume pid fits in int. (fail): Don’t assume pointer difference fits in int. (set_local_socket): Don’t assume uid fits in long.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 2097fece00a..b7d4e813764 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -73,9 +73,11 @@ char *w32_getenv (const char *);
73#include <ctype.h> 73#include <ctype.h>
74#include <errno.h> 74#include <errno.h>
75#include <getopt.h> 75#include <getopt.h>
76#include <inttypes.h>
76#include <pwd.h> 77#include <pwd.h>
77#include <signal.h> 78#include <signal.h>
78#include <stdarg.h> 79#include <stdarg.h>
80#include <stddef.h>
79#include <stdlib.h> 81#include <stdlib.h>
80#include <string.h> 82#include <string.h>
81#include <sys/stat.h> 83#include <sys/stat.h>
@@ -144,7 +146,7 @@ static char const *server_file;
144static char const *tramp_prefix; 146static char const *tramp_prefix;
145 147
146/* PID of the Emacs server process. */ 148/* PID of the Emacs server process. */
147static int emacs_pid; 149static pid_t emacs_pid;
148 150
149/* If non-NULL, a string that should form a frame parameter alist to 151/* If non-NULL, a string that should form a frame parameter alist to
150 be used for the new frame. */ 152 be used for the new frame. */
@@ -692,7 +694,7 @@ fail (void)
692 size_t new_argv_size = extra_args_size; 694 size_t new_argv_size = extra_args_size;
693 char **new_argv = xmalloc (new_argv_size); 695 char **new_argv = xmalloc (new_argv_size);
694 char *s = xstrdup (alternate_editor); 696 char *s = xstrdup (alternate_editor);
695 unsigned toks = 0; 697 ptrdiff_t toks = 0;
696 698
697 /* Unpack alternate_editor's space-separated tokens into new_argv. */ 699 /* Unpack alternate_editor's space-separated tokens into new_argv. */
698 for (char *tok = s; tok != NULL && *tok != '\0';) 700 for (char *tok = s; tok != NULL && *tok != '\0';)
@@ -1200,12 +1202,13 @@ set_local_socket (const char *local_socket_name)
1200 char const *tmpdir = NULL; 1202 char const *tmpdir = NULL;
1201 char *tmpdir_storage = NULL; 1203 char *tmpdir_storage = NULL;
1202 char *socket_name_storage = NULL; 1204 char *socket_name_storage = NULL;
1205 static char const subdir_format[] = "/emacs%"PRIuMAX"/";
1203 1206
1204 if (! (strchr (local_socket_name, '/') 1207 if (! (strchr (local_socket_name, '/')
1205 || (ISSLASH ('\\') && strchr (local_socket_name, '\\')))) 1208 || (ISSLASH ('\\') && strchr (local_socket_name, '\\'))))
1206 { 1209 {
1207 /* socket_name is a file name component. */ 1210 /* socket_name is a file name component. */
1208 long uid = geteuid (); 1211 uintmax_t uid = geteuid ();
1209 tmpdir = egetenv ("TMPDIR"); 1212 tmpdir = egetenv ("TMPDIR");
1210 if (!tmpdir) 1213 if (!tmpdir)
1211 { 1214 {
@@ -1226,7 +1229,7 @@ set_local_socket (const char *local_socket_name)
1226 socket_name_storage = 1229 socket_name_storage =
1227 xmalloc (strlen (tmpdir) + strlen (server_name) + EXTRA_SPACE); 1230 xmalloc (strlen (tmpdir) + strlen (server_name) + EXTRA_SPACE);
1228 char *z = stpcpy (socket_name_storage, tmpdir); 1231 char *z = stpcpy (socket_name_storage, tmpdir);
1229 z += sprintf (z, "/emacs%ld/", uid); 1232 z += sprintf (z, subdir_format, uid);
1230 strcpy (z, server_name); 1233 strcpy (z, server_name);
1231 local_socket_name = socket_name_storage; 1234 local_socket_name = socket_name_storage;
1232 } 1235 }
@@ -1262,12 +1265,12 @@ set_local_socket (const char *local_socket_name)
1262 if (pw && (pw->pw_uid != geteuid ())) 1265 if (pw && (pw->pw_uid != geteuid ()))
1263 { 1266 {
1264 /* We're running under su, apparently. */ 1267 /* We're running under su, apparently. */
1265 long uid = pw->pw_uid; 1268 uintmax_t uid = pw->pw_uid;
1266 char *user_socket_name 1269 char *user_socket_name
1267 = xmalloc (strlen (tmpdir) + strlen (server_name) 1270 = xmalloc (strlen (tmpdir) + strlen (server_name)
1268 + EXTRA_SPACE); 1271 + EXTRA_SPACE);
1269 char *z = stpcpy (user_socket_name, tmpdir); 1272 char *z = stpcpy (user_socket_name, tmpdir);
1270 z += sprintf (z, "/emacs%ld/", uid); 1273 z += sprintf (z, subdir_format, uid);
1271 strcpy (z, server_name); 1274 strcpy (z, server_name);
1272 1275
1273 if (strlen (user_socket_name) < sizeof (server.sun_path)) 1276 if (strlen (user_socket_name) < sizeof (server.sun_path))
@@ -1848,7 +1851,7 @@ main (int argc, char **argv)
1848 if (strprefix ("-emacs-pid ", p)) 1851 if (strprefix ("-emacs-pid ", p))
1849 { 1852 {
1850 /* -emacs-pid PID: The process id of the Emacs process. */ 1853 /* -emacs-pid PID: The process id of the Emacs process. */
1851 emacs_pid = strtol (p + strlen ("-emacs-pid"), NULL, 10); 1854 emacs_pid = strtoumax (p + strlen ("-emacs-pid"), NULL, 10);
1852 } 1855 }
1853 else if (strprefix ("-window-system-unsupported ", p)) 1856 else if (strprefix ("-window-system-unsupported ", p))
1854 { 1857 {