S/390: Add hwcap value for transactional execution.
[platform/upstream/glibc.git] / misc / getusershell.c
index 255b579..2e8d97e 100644 (file)
@@ -98,13 +98,13 @@ initshells()
        register char **sp, *cp;
        register FILE *fp;
        struct stat64 statb;
-       int flen;
+       size_t flen;
 
        free(shells);
        shells = NULL;
        free(strings);
        strings = NULL;
-       if ((fp = fopen(_PATH_SHELLS, "rc")) == NULL)
+       if ((fp = fopen(_PATH_SHELLS, "rce")) == NULL)
                goto init_okshells_noclose;
        if (fstat64(fileno(fp), &statb) == -1) {
        init_okshells:
@@ -114,9 +114,12 @@ initshells()
                okshells[1] = _PATH_CSHELL;
                return (char **) okshells;
        }
-       if ((strings = malloc((u_int)statb.st_size + 1)) == NULL)
+       if (statb.st_size > ~(size_t)0 / sizeof (char *) * 3)
                goto init_okshells;
-       shells = calloc((unsigned)statb.st_size / 3, sizeof (char *));
+       flen = statb.st_size + 3;
+       if ((strings = malloc(flen)) == NULL)
+               goto init_okshells;
+       shells = malloc(statb.st_size / 3 * sizeof (char *));
        if (shells == NULL) {
                free(strings);
                strings = NULL;
@@ -124,11 +127,10 @@ initshells()
        }
        sp = shells;
        cp = strings;
-       flen = statb.st_size;
        while (fgets_unlocked(cp, flen - (cp - strings), fp) != NULL) {
                while (*cp != '#' && *cp != '/' && *cp != '\0')
                        cp++;
-               if (*cp == '#' || *cp == '\0')
+               if (*cp == '#' || *cp == '\0' || cp[1] == '\0')
                        continue;
                *sp++ = cp;
                while (!isspace(*cp) && *cp != '#' && *cp != '\0')