]> code.delx.au - gnu-emacs/commitdiff
Fix bug #12621 with crashes on MS-Windows in LookupAccountSid.
authorEli Zaretskii <eliz@gnu.org>
Fri, 14 Dec 2012 09:09:36 +0000 (11:09 +0200)
committerEli Zaretskii <eliz@gnu.org>
Fri, 14 Dec 2012 09:09:36 +0000 (11:09 +0200)
 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.

src/ChangeLog
src/w32.c

index 5239559f867288caefd3ec5c58c51058a0bec729..fe30528da9167086226f4d58553ced36382e0366 100644 (file)
@@ -1,3 +1,12 @@
+2012-12-14  Eli Zaretskii  <eliz@gnu.org>
+
+       * 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.
+
 2012-12-11  Eli Zaretskii  <eliz@gnu.org>
 
        * search.c (search_buffer): Check the inverse translations of each
index fc97b0b490b6d60c7ed5544dd465303f92ea8bf6..edb9b1b6189277a8cb13272aded9476dbd185c81 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -3362,8 +3362,7 @@ w32_add_to_cache (PSID sid, unsigned id, char *name)
 #define GID 2
 
 static int
-get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
-                unsigned *id, char *nm, int what)
+get_name_and_id (PSECURITY_DESCRIPTOR psd, unsigned *id, char *nm, int what)
 {
   PSID sid = NULL;
   char machine[MAX_COMPUTERNAME_LENGTH+1];
@@ -3373,7 +3372,6 @@ get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
   DWORD name_len = sizeof (name);
   char domain[1024];
   DWORD domain_len = sizeof (domain);
-  char *mp = NULL;
   int use_dflt = 0;
   int result;
 
@@ -3388,22 +3386,7 @@ get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
     use_dflt = 1;
   else if (!w32_cached_id (sid, id, nm))
     {
-      /* If FNAME is a UNC, we need to lookup account on the
-        specified machine.  */
-      if (IS_DIRECTORY_SEP (fname[0]) && IS_DIRECTORY_SEP (fname[1])
-         && fname[2] != '\0')
-       {
-         const char *s;
-         char *p;
-
-         for (s = fname + 2, p = machine;
-              *s && !IS_DIRECTORY_SEP (*s); s++, p++)
-           *p = *s;
-         *p = '\0';
-         mp = machine;
-       }
-
-      if (!lookup_account_sid (mp, sid, name, &name_len,
+      if (!lookup_account_sid (NULL, sid, name, &name_len,
                               domain, &domain_len, &ignore)
          || name_len > UNLEN+1)
        use_dflt = 1;
@@ -3418,9 +3401,7 @@ get_name_and_id (PSECURITY_DESCRIPTOR psd, const char *fname,
 }
 
 static void
-get_file_owner_and_group (PSECURITY_DESCRIPTOR psd,
-                         const char *fname,
-                         struct stat *st)
+get_file_owner_and_group (PSECURITY_DESCRIPTOR psd, struct stat *st)
 {
   int dflt_usr = 0, dflt_grp = 0;
 
@@ -3431,9 +3412,9 @@ get_file_owner_and_group (PSECURITY_DESCRIPTOR psd,
     }
   else
     {
-      if (get_name_and_id (psd, fname, &st->st_uid, st->st_uname, UID))
+      if (get_name_and_id (psd, &st->st_uid, st->st_uname, UID))
        dflt_usr = 1;
-      if (get_name_and_id (psd, fname, &st->st_gid, st->st_gname, GID))
+      if (get_name_and_id (psd, &st->st_gid, st->st_gname, GID))
        dflt_grp = 1;
     }
   /* 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)
        psd = get_file_security_desc_by_handle (fh);
       if (psd)
        {
-         get_file_owner_and_group (psd, name, buf);
+         get_file_owner_and_group (psd, buf);
          LocalFree (psd);
        }
       else if (is_windows_9x () == TRUE)
-       get_file_owner_and_group (NULL, name, buf);
+       get_file_owner_and_group (NULL, buf);
       else if (!(is_a_symlink && follow_symlinks))
        {
          psd = get_file_security_desc_by_name (name);
-         get_file_owner_and_group (psd, name, buf);
+         get_file_owner_and_group (psd, buf);
          xfree (psd);
        }
       else
-       get_file_owner_and_group (NULL, name, buf);
+       get_file_owner_and_group (NULL, buf);
       CloseHandle (fh);
     }
   else
@@ -3775,7 +3756,7 @@ stat_worker (const char * path, struct stat * buf, int follow_symlinks)
       else
        buf->st_mode = S_IFREG;
 
-      get_file_owner_and_group (NULL, name, buf);
+      get_file_owner_and_group (NULL, buf);
     }
 
 #if 0