Changeset 943 in openpam for trunk/lib


Ignore:
Timestamp:
Feb 20, 2019, 1:23:51 PM (20 months ago)
Author:
Dag-Erling Smørgrav
Message:

Fix an off-by-one bug in pam_getenv() which was inadvertantly
introduced when pam_getenv() was (needlessly) rewritten as part of
r913. Rewrite pam_getenv() again (but correctly, this time) to reduce
the number of times we iterate over the same string. Add a few unit
tests for pam_{get,put,set}env(), including one which would have
caught the bug.

Credit goes to Tim Creech <tcreech@…> for discovering and
reporting the bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/libpam/pam_getenv.c

    r938 r943  
    5959        const char *name)
    6060{
    61         char *str;
     61        size_t len;
    6262        int i;
    6363
    6464        ENTERS(name);
    65         if (strchr(name, '=') != NULL) {
    66                 errno = EINVAL;
     65        for (len = 0; name[len] != '\0'; ++len) {
     66                if (name[len] == '=') {
     67                        errno = EINVAL;
     68                        RETURNS(NULL);
     69                }
     70        }
     71        if ((i = openpam_findenv(pamh, name, len)) < 0)
    6772                RETURNS(NULL);
    68         }
    69         if ((i = openpam_findenv(pamh, name, strlen(name))) < 0)
    70                 RETURNS(NULL);
    71         if ((str = strchr(pamh->env[i], '=')) == NULL)
    72                 RETURNS("");
    73         RETURNS(str);
     73        /* assert(pamh->env[i][len] == '='); */
     74        RETURNS(pamh->env[i] + len + 1);
    7475}
    7576
Note: See TracChangeset for help on using the changeset viewer.