aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2012-12-14 11:09:36 +0200
committerEli Zaretskii2012-12-14 11:09:36 +0200
commit92340ec75375cc92b5024296817f5bb7f989135f (patch)
tree7055e019cfae1bf03bd2633388d9f6e27cf7d045 /src
parent1e20eeb758c5c78055962c6de6ee6ac2b49b8a02 (diff)
downloademacs-92340ec75375cc92b5024296817f5bb7f989135f.tar.gz
emacs-92340ec75375cc92b5024296817f5bb7f989135f.zip
Fix bug #12621 with crashes on MS-Windows in LookupAccountSid.
src/w32.c (get_name_and_id): Always pass NULL as the first argument of lookup_account_sid. Avoids crashes with UNC file names that refer to DFS domains, not to specific machine names. (Bug#12621) Remove now unused argument FNAME; all callers changed. (get_file_owner_and_group): Remove now unused argument FNAME; all callers changed.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/w32.c39
2 files changed, 19 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5239559f867..fe30528da91 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12012-12-14 Eli Zaretskii <eliz@gnu.org>
2
3 * w32.c (get_name_and_id): Always pass NULL as the first argument
4 of lookup_account_sid. Avoids crashes with UNC file names that
5 refer to DFS domains, not to specific machine names. (Bug#12621)
6 Remove now unused argument FNAME; all callers changed.
7 (get_file_owner_and_group): Remove now unused argument FNAME; all
8 callers changed.
9
12012-12-11 Eli Zaretskii <eliz@gnu.org> 102012-12-11 Eli Zaretskii <eliz@gnu.org>
2 11
3 * search.c (search_buffer): Check the inverse translations of each 12 * search.c (search_buffer): Check the inverse translations of each
diff --git a/src/w32.c b/src/w32.c
index fc97b0b490b..edb9b1b6189 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -3362,8 +3362,7 @@ w32_add_to_cache (PSID sid, unsigned id, char *name)
3362#define GID 2 3362#define GID 2
3363 3363
3364static int 3364static int
3365get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname, 3365get_name_and_id (PSECURITY_DESCRIPTOR psd, unsigned *id, char *nm, int what)
3366 unsigned *id, char *nm, int what)
3367{ 3366{
3368 PSID sid = NULL; 3367 PSID sid = NULL;
3369 char machine[MAX_COMPUTERNAME_LENGTH+1]; 3368 char machine[MAX_COMPUTERNAME_LENGTH+1];
@@ -3373,7 +3372,6 @@ get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
3373 DWORD name_len = sizeof (name); 3372 DWORD name_len = sizeof (name);
3374 char domain[1024]; 3373 char domain[1024];
3375 DWORD domain_len = sizeof (domain); 3374 DWORD domain_len = sizeof (domain);
3376 char *mp = NULL;
3377 int use_dflt = 0; 3375 int use_dflt = 0;
3378 int result; 3376 int result;
3379 3377
@@ -3388,22 +3386,7 @@ get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
3388 use_dflt = 1; 3386 use_dflt = 1;
3389 else if (!w32_cached_id (sid, id, nm)) 3387 else if (!w32_cached_id (sid, id, nm))
3390 { 3388 {
3391 /* If FNAME is a UNC, we need to lookup account on the 3389 if (!lookup_account_sid (NULL, sid, name, &name_len,
3392 specified machine. */
3393 if (IS_DIRECTORY_SEP (fname[0]) && IS_DIRECTORY_SEP (fname[1])
3394 && fname[2] != '\0')
3395 {
3396 const char *s;
3397 char *p;
3398
3399 for (s = fname + 2, p = machine;
3400 *s && !IS_DIRECTORY_SEP (*s); s++, p++)
3401 *p = *s;
3402 *p = '\0';
3403 mp = machine;
3404 }
3405
3406 if (!lookup_account_sid (mp, sid, name, &name_len,
3407 domain, &domain_len, &ignore) 3390 domain, &domain_len, &ignore)
3408 || name_len > UNLEN+1) 3391 || name_len > UNLEN+1)
3409 use_dflt = 1; 3392 use_dflt = 1;
@@ -3418,9 +3401,7 @@ get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
3418} 3401}
3419 3402
3420static void 3403static void
3421get_file_owner_and_group (PSECURITY_DESCRIPTOR psd, 3404get_file_owner_and_group (PSECURITY_DESCRIPTOR psd, struct stat *st)
3422 const char *fname,
3423 struct stat *st)
3424{ 3405{
3425 int dflt_usr = 0, dflt_grp = 0; 3406 int dflt_usr = 0, dflt_grp = 0;
3426 3407
@@ -3431,9 +3412,9 @@ get_file_owner_and_group (PSECURITY_DESCRIPTOR psd,
3431 } 3412 }
3432 else 3413 else
3433 { 3414 {
3434 if (get_name_and_id (psd, fname, &st->st_uid, st->st_uname, UID)) 3415 if (get_name_and_id (psd, &st->st_uid, st->st_uname, UID))
3435 dflt_usr = 1; 3416 dflt_usr = 1;
3436 if (get_name_and_id (psd, fname, &st->st_gid, st->st_gname, GID)) 3417 if (get_name_and_id (psd, &st->st_gid, st->st_gname, GID))
3437 dflt_grp = 1; 3418 dflt_grp = 1;
3438 } 3419 }
3439 /* Consider files to belong to current user/group, if we cannot get 3420 /* Consider files to belong to current user/group, if we cannot get
@@ -3655,19 +3636,19 @@ stat_worker (const char * path, struct stat * buf, int follow_symlinks)
3655 psd = get_file_security_desc_by_handle (fh); 3636 psd = get_file_security_desc_by_handle (fh);
3656 if (psd) 3637 if (psd)
3657 { 3638 {
3658 get_file_owner_and_group (psd, name, buf); 3639 get_file_owner_and_group (psd, buf);
3659 LocalFree (psd); 3640 LocalFree (psd);
3660 } 3641 }
3661 else if (is_windows_9x () == TRUE) 3642 else if (is_windows_9x () == TRUE)
3662 get_file_owner_and_group (NULL, name, buf); 3643 get_file_owner_and_group (NULL, buf);
3663 else if (!(is_a_symlink && follow_symlinks)) 3644 else if (!(is_a_symlink && follow_symlinks))
3664 { 3645 {
3665 psd = get_file_security_desc_by_name (name); 3646 psd = get_file_security_desc_by_name (name);
3666 get_file_owner_and_group (psd, name, buf); 3647 get_file_owner_and_group (psd, buf);
3667 xfree (psd); 3648 xfree (psd);
3668 } 3649 }
3669 else 3650 else
3670 get_file_owner_and_group (NULL, name, buf); 3651 get_file_owner_and_group (NULL, buf);
3671 CloseHandle (fh); 3652 CloseHandle (fh);
3672 } 3653 }
3673 else 3654 else
@@ -3775,7 +3756,7 @@ stat_worker (const char * path, struct stat * buf, int follow_symlinks)
3775 else 3756 else
3776 buf->st_mode = S_IFREG; 3757 buf->st_mode = S_IFREG;
3777 3758
3778 get_file_owner_and_group (NULL, name, buf); 3759 get_file_owner_and_group (NULL, buf);
3779 } 3760 }
3780 3761
3781#if 0 3762#if 0