Don't rely on signed integer overflowing to negative value.
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 23 Jan 2008 16:48:40 +0000 (17:48 +0100)
committerJim Meyering <meyering@redhat.com>
Wed, 13 Feb 2008 16:15:59 +0000 (17:15 +0100)
* lib/getugroups.c (getugroups): Include <limits.h>.
Instead, compare against INT_MAX, and increment only if the test passes.

ChangeLog
lib/getugroups.c

index 155d5f7be8feded1a3784d17089f05fb73a2285b..a7ef8fb4be89b1f531ad11980bf555bca947c1fc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-02-13  Lasse Collin  <lasse.collin@tukaani.org>
+
+       Don't rely on signed integer overflowing to negative value.
+       * lib/getugroups.c (getugroups): Include <limits.h>.
+       Instead, compare against INT_MAX, and increment only if the test passes.
+
 2008-02-13  Jim Meyering  <meyering@redhat.com>
        and Eric Blake  <ebb9@byu.net>
 
index 6c557cdf341fa55c5d9c2e338a4f3910a34b9552..4b8752f6b669d564f04561e3bb3bba07d19feb87 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "getugroups.h"
 
+#include <limits.h>
 #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */
 #include <grp.h>
 
@@ -92,12 +93,12 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char const *username,
                    goto done;
                  grouplist[count] = grp->gr_gid;
                }
-             count++;
-             if (count < 0)
+             if (count == INT_MAX)
                {
                  errno = EOVERFLOW;
                  goto done;
                }
+             count++;
            }
        }
     }