aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-03-27 12:10:44 -0700
committerPaul Eggert2015-03-27 12:11:08 -0700
commit01d1024bec7781066440104ebee0b186382e10f3 (patch)
treec468355d2eb02cd8b286bd2b4dfe00832624f8ad /src
parent589a4034b7af522c5b8107d5089fb1aec523a1e4 (diff)
downloademacs-01d1024bec7781066440104ebee0b186382e10f3.tar.gz
emacs-01d1024bec7781066440104ebee0b186382e10f3.zip
Avoid some core dumps in X session management
Derived from a bug report by Nicolas Richard in: http://bugs.gnu.org/20191#20 * xsmfns.c (smc_save_yourself_CB): Don't dump core if invocation-name is not a string. Initialize user-login-name if it is not already initialized, and don't dump core if it is not a string. (create_client_leader_window): Don't dump core if x-resource-name and x-resource-class are not both strings. (x_session_initialize): Don't dump core if x-session-previous-id, invocation-directory, and invocation-name are not strings.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog14
-rw-r--r--src/xsmfns.c57
2 files changed, 47 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 61f2a84a9f9..db3056ce6bd 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,20 @@
12015-03-27 Paul Eggert <eggert@cs.ucla.edu> 12015-03-27 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 Avoid some core dumps in X session management
4 Derived from a bug report by Nicolas Richard in:
5 http://bugs.gnu.org/20191#20
6 * xsmfns.c (smc_save_yourself_CB): Don't dump core if
7 invocation-name is not a string. Initialize user-login-name if it
8 is not already initialized, and don't dump core if it is not a
9 string.
10 (create_client_leader_window): Don't dump core if x-resource-name
11 and x-resource-class are not both strings.
12 (x_session_initialize): Don't dump core if x-session-previous-id,
13 invocation-directory, and invocation-name are not strings.
14
3 Port user-login-name initialization to Qnil == 0 15 Port user-login-name initialization to Qnil == 0
16 Derived from a bug report by Nicolas Richard in:
17 http://bugs.gnu.org/20191#20
4 * editfns.c (Fuser_login_name, Fuser_real_login_name) 18 * editfns.c (Fuser_login_name, Fuser_real_login_name)
5 (syms_of_editfns): Don't rely on all-bits-zero being an Elisp integer, 19 (syms_of_editfns): Don't rely on all-bits-zero being an Elisp integer,
6 as this is no longer true now that Qnil == 0. 20 as this is no longer true now that Qnil == 0.
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 0e635d38ec6..375b51c4466 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -168,7 +168,6 @@ smc_save_yourself_CB (SmcConn smcConn,
168 int val_idx = 0, vp_idx = 0; 168 int val_idx = 0, vp_idx = 0;
169 int props_idx = 0; 169 int props_idx = 0;
170 int i; 170 int i;
171 char *cwd = get_current_dir_name ();
172 char *smid_opt, *chdir_opt = NULL; 171 char *smid_opt, *chdir_opt = NULL;
173 172
174 /* How to start a new instance of Emacs. */ 173 /* How to start a new instance of Emacs. */
@@ -181,27 +180,34 @@ smc_save_yourself_CB (SmcConn smcConn,
181 props[props_idx]->vals[0].value = emacs_program; 180 props[props_idx]->vals[0].value = emacs_program;
182 ++props_idx; 181 ++props_idx;
183 182
184 /* The name of the program. */ 183 if (STRINGP (Vinvocation_name))
185 props[props_idx] = &prop_ptr[props_idx]; 184 {
186 props[props_idx]->name = xstrdup (SmProgram); 185 /* The name of the program. */
187 props[props_idx]->type = xstrdup (SmARRAY8); 186 props[props_idx] = &prop_ptr[props_idx];
188 props[props_idx]->num_vals = 1; 187 props[props_idx]->name = xstrdup (SmProgram);
189 props[props_idx]->vals = &values[val_idx++]; 188 props[props_idx]->type = xstrdup (SmARRAY8);
190 props[props_idx]->vals[0].length = SBYTES (Vinvocation_name); 189 props[props_idx]->num_vals = 1;
191 props[props_idx]->vals[0].value = SDATA (Vinvocation_name); 190 props[props_idx]->vals = &values[val_idx++];
192 ++props_idx; 191 props[props_idx]->vals[0].length = SBYTES (Vinvocation_name);
192 props[props_idx]->vals[0].value = SDATA (Vinvocation_name);
193 ++props_idx;
194 }
193 195
194 /* User id. */ 196 /* User id. */
195 props[props_idx] = &prop_ptr[props_idx]; 197 Lisp_Object user_login_name = Fuser_login_name (Qnil);
196 props[props_idx]->name = xstrdup (SmUserID); 198 if (STRINGP (user_login_name))
197 props[props_idx]->type = xstrdup (SmARRAY8); 199 {
198 props[props_idx]->num_vals = 1; 200 props[props_idx] = &prop_ptr[props_idx];
199 props[props_idx]->vals = &values[val_idx++]; 201 props[props_idx]->name = xstrdup (SmUserID);
200 props[props_idx]->vals[0].length = SBYTES (Vuser_login_name); 202 props[props_idx]->type = xstrdup (SmARRAY8);
201 props[props_idx]->vals[0].value = SDATA (Vuser_login_name); 203 props[props_idx]->num_vals = 1;
202 ++props_idx; 204 props[props_idx]->vals = &values[val_idx++];
203 205 props[props_idx]->vals[0].length = SBYTES (user_login_name);
206 props[props_idx]->vals[0].value = SDATA (user_login_name);
207 ++props_idx;
208 }
204 209
210 char *cwd = get_current_dir_name ();
205 if (cwd) 211 if (cwd)
206 { 212 {
207 props[props_idx] = &prop_ptr[props_idx]; 213 props[props_idx] = &prop_ptr[props_idx];
@@ -372,6 +378,7 @@ create_client_leader_window (struct x_display_info *dpyinfo, char *client_ID)
372 -1, -1, 1, 1, 378 -1, -1, 1, 1,
373 CopyFromParent, CopyFromParent, CopyFromParent); 379 CopyFromParent, CopyFromParent, CopyFromParent);
374 380
381 validate_x_resource_name ();
375 class_hints.res_name = SSDATA (Vx_resource_name); 382 class_hints.res_name = SSDATA (Vx_resource_name);
376 class_hints.res_class = SSDATA (Vx_resource_class); 383 class_hints.res_class = SSDATA (Vx_resource_class);
377 XSetClassHint (dpyinfo->display, w, &class_hints); 384 XSetClassHint (dpyinfo->display, w, &class_hints);
@@ -402,22 +409,24 @@ x_session_initialize (struct x_display_info *dpyinfo)
402 409
403 /* Check if we where started by the session manager. If so, we will 410 /* Check if we where started by the session manager. If so, we will
404 have a previous id. */ 411 have a previous id. */
405 if (! NILP (Vx_session_previous_id) && STRINGP (Vx_session_previous_id)) 412 if (STRINGP (Vx_session_previous_id))
406 previous_id = SSDATA (Vx_session_previous_id); 413 previous_id = SSDATA (Vx_session_previous_id);
407 414
408 /* Construct the path to the Emacs program. */ 415 /* Construct the path to the Emacs program. */
409 if (! NILP (Vinvocation_directory)) 416 if (STRINGP (Vinvocation_directory))
410 name_len += SBYTES (Vinvocation_directory); 417 name_len += SBYTES (Vinvocation_directory);
411 name_len += SBYTES (Vinvocation_name); 418 if (STRINGP (Vinvocation_name))
419 name_len += SBYTES (Vinvocation_name);
412 420
413 /* This malloc will not be freed, but it is only done once, and hopefully 421 /* This malloc will not be freed, but it is only done once, and hopefully
414 not very large */ 422 not very large */
415 emacs_program = xmalloc (name_len + 1); 423 emacs_program = xmalloc (name_len + 1);
416 char *z = emacs_program; 424 char *z = emacs_program;
417 425
418 if (! NILP (Vinvocation_directory)) 426 if (STRINGP (Vinvocation_directory))
419 z = lispstpcpy (z, Vinvocation_directory); 427 z = lispstpcpy (z, Vinvocation_directory);
420 lispstpcpy (z, Vinvocation_name); 428 if (STRINGP (Vinvocation_name))
429 lispstpcpy (z, Vinvocation_name);
421 430
422 /* The SM protocol says all callbacks are mandatory, so set up all 431 /* The SM protocol says all callbacks are mandatory, so set up all
423 here and in the mask passed to SmcOpenConnection. */ 432 here and in the mask passed to SmcOpenConnection. */