lib: Fix integer overflowed argument issue with strtoul()
authorAndreas Schneider <asn@samba.org>
Thu, 3 Aug 2017 08:52:59 +0000 (10:52 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 3 Aug 2017 13:06:34 +0000 (15:06 +0200)
This fixes CID 1415704

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Aug  3 15:06:34 CEST 2017 on sn-devel-144

lib/uid_wrapper/uid_wrapper.c

index cb31c5e8b009e25812959972f870845e6004019d..8f41ed92cb953b72c10e6a22485abbe5f59339c9 100644 (file)
@@ -1029,7 +1029,21 @@ static void uwrap_init_env(struct uwrap_thread *id)
                unsetenv("UID_WRAPPER_INITIAL_GROUPS_COUNT");
        }
 
-       if (ngroups > 0 && ngroups < GROUP_MAX_COUNT) {
+       env = getenv("UID_WRAPPER_INITIAL_GROUPS_COUNT");
+       if (env != NULL && env[0] != '\0') {
+               char *endp = NULL;
+               long n;
+
+               n = strtol(env, &endp, 10);
+               if (env == endp) {
+                       ngroups = 0;
+               } else if (n > 0 && n < GROUP_MAX_COUNT) {
+                       ngroups = (int)n;
+               }
+               unsetenv("UID_WRAPPER_INITIAL_GROUPS_COUNT");
+       }
+
+       if (ngroups > 0) {
                int i = 0;
 
                id->ngroups = 0;