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

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