[PATCH] 32bit ID patches

Thorsten Kukuk kukuk@suse.de
Wed Nov 21 04:53:00 GMT 2001


Hi,

in some places in glibc code we use signed values for user id and
group id, but with linux they are unsigned. Appended is a patch for
the cases I found.

  Thorsten
-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE GmbH            Deutschherrenstr. 15-19       D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------
2001-11-22  Thorsten Kukuk  <kukuk@suse.de>

	* nis/nss_compat/compat-grp.c: Print group id as unsigned long.
	* nis/nss_nis/nis-grp.c: Likewise.
	* nis/nss_nisplus/nisplus-grp.c: Likewise.
	
	* nis/nss_comapt/compat-pwd.c: Print user id as unsigned long.
	* nis/nss_nis/nis-pwd: Likewise.
	* nis/nss_nisplus/nisplus-pwd.c: Likewise.

	* nis/nss_nis/nis-publickey.c: Use strtoul instead of atoi.
	* nis/nss_nisplus/nisplus-parser.c: Likewise.
	* nis/nss_nisplus/nisplus-publickey.c: Likewise.

	* nscd/grpcache.c: Use strtoul instead of atol.
	* nscd/pwdcache.c: Likewise.
	* nss/getent.c: Likewise.

--- nis/nss_compat/compat-grp.c
+++ nis/nss_compat/compat-grp.c	2001/09/03 10:22:46
@@ -764,7 +764,7 @@
       nis_result *res;
       char buf[24 + grptablelen];
 
-      sprintf(buf, "[gid=%d],%s", gid, grptable);
+      sprintf(buf, "[gid=%lu],%s", (unsigned long) gid, grptable);
       res = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
       if (niserr2nss (res->status) != NSS_STATUS_SUCCESS)
         {
@@ -794,7 +794,7 @@
 	  return NSS_STATUS_NOTFOUND;
 	}
 
-      snprintf (buf, sizeof (buf), "%d", gid);
+      snprintf (buf, sizeof (buf), "%lu", (unsigned long) gid);
 
       if (yp_match (domain, "group.bygid", buf, strlen (buf),
 		    &outval, &outvallen) != YPERR_SUCCESS)
--- nis/nss_compat/compat-pwd.c
+++ nis/nss_compat/compat-pwd.c	2001/09/03 10:21:05
@@ -1353,8 +1353,9 @@
       nis_result *res;
       char buf[1024 + pwdtablelen];
 
-      snprintf(buf, sizeof (buf), "[uid=%d],%s", uid, pwdtable);
-      res = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+      snprintf (buf, sizeof (buf), "[uid=%lu],%s", (unsigned long) uid, 
+                pwdtable);
+      res = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
       if (niserr2nss (res->status) != NSS_STATUS_SUCCESS)
         {
           enum nss_status status =  niserr2nss (res->status);
@@ -1383,7 +1384,7 @@
           return NSS_STATUS_NOTFOUND;
         }
 
-      sprintf (buf, "%d", uid);
+      sprintf (buf, "%lu", (unsigned long) uid);
       if (yp_match (domain, "passwd.byuid", buf, strlen (buf),
                     &outval, &outvallen)
           != YPERR_SUCCESS)
--- nis/nss_nis/nis-grp.c
+++ nis/nss_nis/nis-grp.c	2001/09/03 13:09:09
@@ -227,7 +227,7 @@
   if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  nlen = sprintf (buf, "%d", gid);
+  nlen = sprintf (buf, "%lu", (unsigned long) gid);
 
   retval = yperr2nss (yp_match (domain, "group.bygid", buf,
 				nlen, &result, &len));
--- nis/nss_nis/nis-publickey.c
+++ nis/nss_nis/nis-publickey.c	2001/09/03 13:32:39
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -143,7 +143,7 @@
 parse_netid_str (const char *s, uid_t *uidp, gid_t *gidp, int *gidlenp,
 		 gid_t *gidlist)
 {
-  char *p;
+  char *p, *ep;
   int gidlen;
 
   if (!s || !isdigit (*s))
@@ -153,7 +153,7 @@
     }
 
   /* Fetch the uid */
-  *uidp = (atoi (s));
+  *uidp = strtoul (s, NULL, 10);
 
   if (*uidp == 0)
     {
@@ -175,14 +175,17 @@
       return NSS_STATUS_NOTFOUND;
     }
 
-  *gidp = (atoi (p));
+  *gidp = strtoul (p, &ep, 10);
 
   gidlen = 0;
 
-  while ((p = strchr (p, ',')) != NULL)
-    {
-      p++;
-      gidlist[gidlen++] = atoi (p);
+  /* After strtoul() ep should point to the first invalid character.
+     This is the marker "," we search for the next value.  */ 
+  while (ep != NULL && *ep == ',')
+    {
+      ep++;
+      p = ep;
+      gidlist[gidlen++] = strtoul (p, &ep, 10);
     }
 
   *gidlenp = gidlen;
--- nis/nss_nis/nis-pwd.c
+++ nis/nss_nis/nis-pwd.c	2001/09/03 13:09:36
@@ -329,7 +329,7 @@
   if (yp_get_default_domain (&domain))
     return NSS_STATUS_UNAVAIL;
 
-  nlen = sprintf (buf, "%d", uid);
+  nlen = sprintf (buf, "%lu", (unsigned long) uid);
 
   retval = yperr2nss (yp_match (domain, "passwd.byuid", buf,
 				nlen, &result, &len));
--- nis/nss_nisplus/nisplus-grp.c
+++ nis/nss_nisplus/nisplus-grp.c	2001/09/03 12:31:05
@@ -227,7 +227,7 @@
     nis_result *result;
     char buf[36 + tablename_len];
 
-    sprintf (buf, "[gid=%d],%s", gid, tablename_val);
+    sprintf (buf, "[gid=%lu],%s", (unsigned long) gid, tablename_val);
 
     result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
 
--- nis/nss_nisplus/nisplus-parser.c
+++ nis/nss_nisplus/nisplus-parser.c	2001/09/03 13:24:37
@@ -89,7 +89,7 @@
   len = strlen (first_unused);
   if (len == 0) /* If we don't have a uid, it's an invalid shadow entry */
     return 0;
-  pw->pw_uid = atoi (first_unused);
+  pw->pw_uid = strtoul (first_unused, NULL, 10);
   room_left -= (len + 1);
   first_unused += (len + 1);
 
@@ -102,7 +102,7 @@
   len = strlen (first_unused);
   if (len == 0) /* If we don't have a gid, it's an invalid shadow entry */
     return 0;
-  pw->pw_gid = atoi (first_unused);
+  pw->pw_gid = strtoul (first_unused, NULL, 10);
   room_left -= (len + 1);
   first_unused += (len + 1);
 
@@ -200,7 +200,7 @@
   len = strlen (first_unused);
   if (len == 0) /* We should always have an gid */
     return 0;
-  gr->gr_gid = atoi (first_unused);
+  gr->gr_gid = strtoul (first_unused, NULL, 10);
   room_left -= (strlen (first_unused) + 1);
   first_unused += strlen (first_unused) + 1;
 
--- nis/nss_nisplus/nisplus-publickey.c
+++ nis/nss_nisplus/nisplus-publickey.c	2001/09/03 13:34:02
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1999 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1999, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -200,6 +200,7 @@
 parse_grp_str (const char *s, gid_t *gidp, int *gidlenp, gid_t *gidlist,
 	       int *errnop)
 {
+  char *ep;
   int gidlen;
 
   if (!s || (!isdigit (*s)))
@@ -208,14 +209,17 @@
       return NSS_STATUS_NOTFOUND;
     }
 
-  *gidp = atoi (s);
+  *gidp = strtoul (s, &ep, 10);
 
   gidlen = 0;
 
-  while ((s = strchr (s, ',')) != NULL)
-    {
-      s++;
-      gidlist[gidlen++] = atoi (s);
+  /* After strtoul() ep should point to the marker ',', which means
+     here starts a new value. */
+  while (ep != NULL && *ep == ',')
+    {
+      ep++;
+      s = ep;
+      gidlist[gidlen++] = strtoul (s, &ep, 10);
     }
   *gidlenp = gidlen;
 
@@ -368,7 +372,7 @@
 	    _("netname2user: LOCAL entry for %s in directory %s not unique"),
 	    netname, domain);
   /* Fetch the uid */
-  *uidp = atoi (ENTRY_VAL (res->objects.objects_val, 2));
+  *uidp = strtoul (ENTRY_VAL (res->objects.objects_val, 2), NULL, 10);
 
   if (*uidp == 0)
     {
--- nis/nss_nisplus/nisplus-pwd.c
+++ nis/nss_nisplus/nisplus-pwd.c	2001/09/03 12:31:44
@@ -235,7 +235,7 @@
     nis_result *result;
     char buf[100 + tablename_len];
 
-    sprintf (buf, "[uid=%d],%s", uid, tablename_val);
+    sprintf (buf, "[uid=%lu],%s", (unsigned long) uid, tablename_val);
 
     result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
 
--- nscd/grpcache.c
+++ nscd/grpcache.c	2001/09/03 09:53:40
@@ -246,8 +246,18 @@
   char *buffer = alloca (buflen);
   struct group resultbuf;
   struct group *grp;
-  gid_t gid = atol (key);
   uid_t oldeuid = 0;
+  char *ep;
+  gid_t gid = strtoul ((char *)key, &ep, 10); 
+  
+  if (*(char*)key == '\0' || *ep != '\0')  /* invalid numeric gid */
+    {
+      if (debug_level > 0)
+        dbg_log (_("Invalid numeric gid \"%s\"!"), (char *)key);
+
+      errno = EINVAL;
+      return;
+    }
 
   if (debug_level > 0)
     dbg_log (_("Haven't found \"%d\" in group cache!"), gid);
--- nscd/pwdcache.c
+++ nscd/pwdcache.c	2001/09/03 09:54:44
@@ -242,8 +242,18 @@
   char *buffer = alloca (buflen);
   struct passwd resultbuf;
   struct passwd *pwd;
-  uid_t uid = atol (key);
   uid_t oldeuid = 0;
+  char *ep;
+  uid_t uid = strtoul ((char*) key, &ep, 10); 
+  
+  if (*(char*)key == '\0' || *ep != '\0')  /* invalid numeric uid */
+    {
+      if (debug_level > 0) 
+        dbg_log (_("Invalid numeric uid \"%s\"!"), (char *)key);
+
+      errno = EINVAL;
+      return;
+    }
 
   if (debug_level > 0)
     dbg_log (_("Haven't found \"%d\" in password cache!"), uid);
--- nss/getent.c
+++ nss/getent.c	2001/09/03 09:49:02
@@ -198,7 +198,15 @@
   for (i = 0; i < number; ++i)
     {
       if (isdigit (key[i][0]))
-	grp = getgrgid (atol (key[i]));
+	{
+           char *ep;
+           gid_t arg_gid = strtoul (key[i], &ep, 10); 
+
+           if (*key[i] != '\0' && *ep == '\0')  /* valid numeric uid */
+             grp = getgrgid (arg_gid);
+           else
+             grp = NULL;
+	}
       else
 	grp = getgrnam (key[i]);
 
@@ -404,7 +412,15 @@
   for (i = 0; i < number; ++i)
     {
       if (isdigit (key[i][0]))
-	pwd = getpwuid (atol (key[i]));
+        {
+	   char *ep;
+	   uid_t arg_uid = strtoul (key[i], &ep, 10); 
+
+           if (*key[i] != '\0' && *ep == '\0')  /* valid numeric uid */
+	     pwd = getpwuid (arg_uid);
+           else
+             pwd = NULL;
+        }
       else
 	pwd = getpwnam (key[i]);
 


More information about the Libc-hacker mailing list