Blame SOURCES/nss-pam-ldapd-0.8.12-uid-overflow.patch

bdd351
Always use a function that we know will catch out-of-range values for UIDs and
bdd351
GIDs, which are currently unsigned 32-bit numbers everywhere, and which won't
bdd351
produce a result that'll silently be truncated if we store the result in a
bdd351
uid_t or gid_t.
bdd351
--- nss-pam-ldapd/nslcd/common.c
bdd351
+++ nss-pam-ldapd/nslcd/common.c
bdd351
@@ -273,19 +273,23 @@ long int binsid2id(const char *binsid)
bdd351
          ((((long int)binsid[i+2])&0xff)<<16)|((((long int)binsid[i+3])&0xff)<<24);
bdd351
 }
bdd351
 
bdd351
-#ifdef WANT_STRTOUI
bdd351
-/* provide a strtoui() implementation, similar to strtoul() but returning
bdd351
+/* provide a strtoid() implementation, similar to strtoul() but returning
bdd351
    an range-checked unsigned int instead */
bdd351
-unsigned int strtoui(const char *nptr,char **endptr,int base)
bdd351
+unsigned int strtoid(const char *nptr,char **endptr,int base)
bdd351
 {
bdd351
-  unsigned long val;
bdd351
-  val=strtoul(nptr,endptr,base);
bdd351
-  if (val>UINT_MAX)
bdd351
+  long long val;
bdd351
+  /* use the fact that long long is 64-bit, even on 32-bit systems */
bdd351
+  val=strtoll(nptr,endptr,base);
bdd351
+  if (val>UINT32_MAX)
bdd351
   {
bdd351
     errno=ERANGE;
bdd351
-    return UINT_MAX;
bdd351
+    return UINT32_MAX;
bdd351
   }
bdd351
-  /* If errno was set by strtoul, we'll pass it back as-is */
bdd351
-  return (unsigned int)val;
bdd351
+  else if (val < 0)
bdd351
+  {
bdd351
+    errno=EINVAL;
bdd351
+    return UINT32_MAX;
bdd351
+  }
bdd351
+  /* If errno was set, we'll pass it back as-is */
bdd351
+  return (uint32_t)val;
bdd351
 }
bdd351
-#endif /* WANT_STRTOUI */
bdd351
--- nss-pam-ldapd/nslcd/common.h
bdd351
+++ nss-pam-ldapd/nslcd/common.h
bdd351
@@ -139,31 +139,9 @@ int nsswitch_db_uses_ldap(const char *fi
bdd351
 #endif /* _POSIX_HOST_NAME_MAX */
bdd351
 #endif /* not HOST_NAME_MAX */
bdd351
 
bdd351
-/* provide strtouid() function alias */
bdd351
-#if SIZEOF_UID_T == SIZEOF_UNSIGNED_LONG_INT
bdd351
-#define strtouid (uid_t)strtoul
bdd351
-#elif SIZEOF_UID_T == SIZEOF_UNSIGNED_LONG_LONG_INT
bdd351
-#define strtouid (uid_t)strtoull
bdd351
-#elif SIZEOF_UID_T == SIZEOF_UNSIGNED_INT
bdd351
-#define WANT_STRTOUI 1
bdd351
-#define strtouid (uid_t)strtoui
bdd351
-#else
bdd351
-#error unable to find implementation for strtouid()
bdd351
-#endif
bdd351
-
bdd351
-/* provide strtouid() function alias */
bdd351
-#if SIZEOF_GID_T == SIZEOF_UNSIGNED_LONG_INT
bdd351
-#define strtogid (gid_t)strtoul
bdd351
-#elif SIZEOF_GID_T == SIZEOF_UNSIGNED_LONG_LONG_INT
bdd351
-#define strtogid (gid_t)strtoull
bdd351
-#elif SIZEOF_GID_T == SIZEOF_UNSIGNED_INT
bdd351
-#ifndef WANT_STRTOUI
bdd351
-#define WANT_STRTOUI 1
bdd351
-#endif
bdd351
-#define strtogid (uid_t)strtoui
bdd351
-#else
bdd351
-#error unable to find implementation for strtogid()
bdd351
-#endif
bdd351
+uint32_t strtoid(const char *nptr,char **endptr,int base);
bdd351
+#define strtouid (uid_t)strtoid
bdd351
+#define strtogid (gid_t)strtoid
bdd351
 
bdd351
 #ifdef WANT_STRTOUI
bdd351
 /* provide a strtoui() if it is needed */