]> granicus.if.org Git - linux-pam/commitdiff
Relevant BUGIDs:
authorTomas Mraz <tm@t8m.info>
Wed, 30 Mar 2005 10:42:54 +0000 (10:42 +0000)
committerTomas Mraz <tm@t8m.info>
Wed, 30 Mar 2005 10:42:54 +0000 (10:42 +0000)
Purpose of commit: bugfix

Commit summary:
---------------
Fix wrong allocation in _pammodutil_gr* functions.
Raise the limit on allocated memory size.
Don't retry call if not ERANGE or EINTR

modules/pammodutil/modutil_getgrgid.c
modules/pammodutil/modutil_getgrnam.c
modules/pammodutil/modutil_getpwnam.c
modules/pammodutil/modutil_getpwuid.c
modules/pammodutil/modutil_getspnam.c
modules/pammodutil/pammodutil.h

index dcac4f78a320c308f666e15fa2c61f90798a80c4..4520ff556c54e94e13e34e8c23b96bdb62317652 100644 (file)
@@ -57,7 +57,7 @@ struct group *_pammodutil_getgrgid(pam_handle_t *pamh, gid_t gid)
        void *new_buffer;
        struct group *result = NULL;
 
-       new_buffer = realloc(buffer, sizeof(struct passwd) + length);
+       new_buffer = realloc(buffer, sizeof(struct group) + length);
        if (new_buffer == NULL) {
 
            D(("out of memory"));
@@ -71,6 +71,7 @@ struct group *_pammodutil_getgrgid(pam_handle_t *pamh, gid_t gid)
        buffer = new_buffer;
 
        /* make the re-entrant call to get the grp structure */
+       errno = 0;
        status = getgrgid_r(gid, buffer,
                            sizeof(struct group) + (char *) buffer,
                            length, &result);
@@ -120,9 +121,12 @@ struct group *_pammodutil_getgrgid(pam_handle_t *pamh, gid_t gid)
            free(buffer);
            return NULL;
 
+       } else if (errno != ERANGE && errno != EINTR) {
+               /* no sense in repeating the call */
+               break;
        }
        
-       length <<= 1;
+       length <<= 2;
 
     } while (length < PWD_ABSURD_PWD_LENGTH);
 
index 7e2d43ff0ccc340230b883c881d20a970aabd7fb..3750e75de65b34a6a749258c7c5eea4540080c85 100644 (file)
@@ -47,7 +47,7 @@ struct group *_pammodutil_getgrnam(pam_handle_t *pamh, const char *group)
        void *new_buffer;
        struct group *result = NULL;
 
-       new_buffer = realloc(buffer, sizeof(struct passwd) + length);
+       new_buffer = realloc(buffer, sizeof(struct group) + length);
        if (new_buffer == NULL) {
 
            D(("out of memory"));
@@ -61,6 +61,7 @@ struct group *_pammodutil_getgrnam(pam_handle_t *pamh, const char *group)
        buffer = new_buffer;
 
        /* make the re-entrant call to get the grp structure */
+       errno = 0;
        status = getgrnam_r(group, buffer,
                            sizeof(struct group) + (char *) buffer,
                            length, &result);
@@ -109,9 +110,12 @@ struct group *_pammodutil_getgrnam(pam_handle_t *pamh, const char *group)
            free(buffer);
            return NULL;
 
-       }
+       } else if (errno != ERANGE && errno != EINTR) {
+                /* no sense in repeating the call */
+                break;
+        }
        
-       length <<= 1;
+       length <<= 2;
 
     } while (length < PWD_ABSURD_PWD_LENGTH);
 
index 891b0b58aaff9c5f57147da1aa47683ea68105fc..ecef0303daedcb8be365afe06bf79642ad064be5 100644 (file)
@@ -61,6 +61,7 @@ struct passwd *_pammodutil_getpwnam(pam_handle_t *pamh, const char *user)
        buffer = new_buffer;
 
        /* make the re-entrant call to get the pwd structure */
+       errno = 0;
        status = getpwnam_r(user, buffer,
                            sizeof(struct passwd) + (char *) buffer,
                            length, &result);
@@ -109,9 +110,12 @@ struct passwd *_pammodutil_getpwnam(pam_handle_t *pamh, const char *user)
            free(buffer);
            return NULL;
 
-       }
+       } else if (errno != ERANGE && errno != EINTR) {
+                /* no sense in repeating the call */
+                break;
+        }
        
-       length <<= 1;
+       length <<= 2;
 
     } while (length < PWD_ABSURD_PWD_LENGTH);
 
index f28ed4e43bc84e53532208b9345048c6cf306005..602c6b8e2a02bb6dea5b183e6eb9e0e6d9849c1f 100644 (file)
@@ -71,6 +71,7 @@ struct passwd *_pammodutil_getpwuid(pam_handle_t *pamh, uid_t uid)
        buffer = new_buffer;
 
        /* make the re-entrant call to get the pwd structure */
+        errno = 0;
        status = getpwuid_r(uid, buffer,
                            sizeof(struct passwd) + (char *) buffer,
                            length, &result);
@@ -120,9 +121,12 @@ struct passwd *_pammodutil_getpwuid(pam_handle_t *pamh, uid_t uid)
            free(buffer);
            return NULL;
 
-       }
+       } else if (errno != ERANGE && errno != EINTR) {
+                /* no sense in repeating the call */
+                break;
+        }
        
-       length <<= 1;
+       length <<= 2;
 
     } while (length < PWD_ABSURD_PWD_LENGTH);
 
index 325cfd339a497fdd2f642ce296b01bd39e31b37f..72fa29ee128a765c4ea17da831c61dbd04f44fe7 100644 (file)
@@ -61,6 +61,7 @@ struct spwd *_pammodutil_getspnam(pam_handle_t *pamh, const char *user)
        buffer = new_buffer;
 
        /* make the re-entrant call to get the spwd structure */
+        errno = 0;
        status = getspnam_r(user, buffer,
                            sizeof(struct spwd) + (char *) buffer,
                            length, &result);
@@ -109,9 +110,12 @@ struct spwd *_pammodutil_getspnam(pam_handle_t *pamh, const char *user)
            free(buffer);
            return NULL;
 
-       }
+       } else if (errno != ERANGE && errno != EINTR) {
+                /* no sense in repeating the call */
+                break;
+        }
        
-       length <<= 1;
+       length <<= 2;
 
     } while (length < PWD_ABSURD_PWD_LENGTH);
 
index efcc98e1662b3050e2969ecd0deaa745278a5035..fbe81023bc11b3c33207e85e913b535d6e95c5ee 100644 (file)
@@ -13,7 +13,7 @@
 #include <security/_pam_modutil.h>
 
 #define PWD_INITIAL_LENGTH     0x100
-#define PWD_ABSURD_PWD_LENGTH  0x1000
+#define PWD_ABSURD_PWD_LENGTH  0x8000
 
 /* This is a simple cleanup, it just free()s the 'data' memory */
 extern void _pammodutil_cleanup(pam_handle_t *pamh, void *data,