Changeset 913 in openpam for trunk/lib


Ignore:
Timestamp:
Jan 21, 2017, 3:11:12 PM (4 years ago)
Author:
Dag-Erling Smørgrav
Message:

Newer versions of clang take nonnull annotations into account not only
when compiling code that calls the function, but also when compiling the
function itself. This means that NULL checks in the function trigger
condition-always-false warnings. We have a choice between disabling these
warnings, removing the nonnull annotations, or removing the NULL checks.
We prefer to keep the annotations and warnings and remove the checks. In
all cases, passing NULL to the function in question will result in a
segmentation fault, which is often easier to debug than an error return,
especially when most of these checks were for the PAM handle, which can only
be NULL if the caller ignored an error return from pam_start().

Location:
trunk/lib/libpam
Files:
14 edited

Legend:

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

    r890 r913  
    7070
    7171        ENTER();
    72         if (pamh == NULL)
    73                 RETURNC(PAM_SYSTEM_ERR);
    7472
    7573        /* prevent recursion */
  • trunk/lib/libpam/openpam_findenv.c

    r648 r913  
    6060
    6161        ENTER();
    62         if (pamh == NULL)
    63                 RETURNN(-1);
    6462        for (i = 0; i < pamh->env_count; ++i)
    6563                if (strncmp(pamh->env[i], name, len) == 0 &&
  • trunk/lib/libpam/openpam_impl.h

    r648 r913  
    131131 * Internal functions
    132132 */
    133 int              openpam_configure(pam_handle_t *, const char *);
    134 int              openpam_dispatch(pam_handle_t *, int, int);
    135 int              openpam_findenv(pam_handle_t *, const char *, size_t);
    136 pam_module_t    *openpam_load_module(const char *);
    137 void             openpam_clear_chains(pam_chain_t **);
     133int              openpam_configure(pam_handle_t *, const char *)
     134        OPENPAM_NONNULL((1));
     135int              openpam_dispatch(pam_handle_t *, int, int)
     136        OPENPAM_NONNULL((1));
     137int              openpam_findenv(pam_handle_t *, const char *, size_t)
     138        OPENPAM_NONNULL((1,2));
     139pam_module_t    *openpam_load_module(const char *)
     140        OPENPAM_NONNULL((1));
     141void             openpam_clear_chains(pam_chain_t **)
     142        OPENPAM_NONNULL((1));
    138143
    139 int              openpam_check_desc_owner_perms(const char *, int);
    140 int              openpam_check_path_owner_perms(const char *);
     144int              openpam_check_desc_owner_perms(const char *, int)
     145        OPENPAM_NONNULL((1));
     146int              openpam_check_path_owner_perms(const char *)
     147        OPENPAM_NONNULL((1));
    141148
    142149#ifdef OPENPAM_STATIC_MODULES
    143 pam_module_t    *openpam_static(const char *);
     150pam_module_t    *openpam_static(const char *)
     151        OPENPAM_NONNULL((1));
    144152#endif
    145 pam_module_t    *openpam_dynamic(const char *);
     153pam_module_t    *openpam_dynamic(const char *)
     154        OPENPAM_NONNULL((1));
    146155
    147156#define FREE(p)                                 \
  • trunk/lib/libpam/pam_end.c

    r648 r913  
    6161
    6262        ENTER();
    63         if (pamh == NULL)
    64                 RETURNC(PAM_SYSTEM_ERR);
    6563
    6664        /* clear module data */
     
    9290}
    9391
    94 /*
    95  * Error codes:
    96  *
    97  *      PAM_SYSTEM_ERR
    98  */
    99 
    10092/**
    10193 * The =pam_end function terminates a PAM transaction and destroys the
  • trunk/lib/libpam/pam_get_authtok.c

    r902 r913  
    7777
    7878        ENTER();
    79         if (pamh == NULL || authtok == NULL)
    80                 RETURNC(PAM_SYSTEM_ERR);
    8179        *authtok = NULL;
    8280        twice = 0;
  • trunk/lib/libpam/pam_get_data.c

    r648 r913  
    6161
    6262        ENTERS(module_data_name);
    63         if (pamh == NULL)
    64                 RETURNC(PAM_SYSTEM_ERR);
    6563        for (dp = pamh->module_data; dp != NULL; dp = dp->next) {
    6664                if (strcmp(dp->name, module_data_name) == 0) {
     
    7573 * Error codes:
    7674 *
    77  *      PAM_SYSTEM_ERR
    7875 *      PAM_NO_MODULE_DATA
    7976 */
  • trunk/lib/libpam/pam_get_item.c

    r648 r913  
    6060
    6161        ENTERI(item_type);
    62         if (pamh == NULL)
    63                 RETURNC(PAM_SYSTEM_ERR);
    6462        switch (item_type) {
    6563        case PAM_SERVICE:
     
    8785 *
    8886 *      PAM_SYMBOL_ERR
    89  *      PAM_SYSTEM_ERR
    9087 */
    9188
  • trunk/lib/libpam/pam_get_user.c

    r902 r913  
    7070
    7171        ENTER();
    72         if (pamh == NULL || user == NULL)
    73                 RETURNC(PAM_SYSTEM_ERR);
    7472        r = pam_get_item(pamh, PAM_USER, (const void **)user);
    7573        if (r == PAM_SUCCESS && *user != NULL)
  • trunk/lib/libpam/pam_getenv.c

    r648 r913  
    6262
    6363        ENTERS(name);
    64         if (pamh == NULL)
    65                 RETURNS(NULL);
    66         if (name == NULL || strchr(name, '=') != NULL)
     64        if (strchr(name, '=') != NULL)
    6765                RETURNS(NULL);
    6866        if ((i = openpam_findenv(pamh, name, strlen(name))) < 0)
    6967                RETURNS(NULL);
    70         for (str = pamh->env[i]; *str != '\0'; ++str) {
    71                 if (*str == '=') {
    72                         ++str;
    73                         break;
    74                 }
    75         }
     68        if ((str = strchr(pamh->env[i], '=')) == NULL)
     69                RETURNS("");
    7670        RETURNS(str);
    7771}
  • trunk/lib/libpam/pam_getenvlist.c

    r648 r913  
    6161
    6262        ENTER();
    63         if (pamh == NULL)
    64                 RETURNP(NULL);
    6563        envlist = malloc(sizeof(char *) * (pamh->env_count + 1));
    6664        if (envlist == NULL) {
  • trunk/lib/libpam/pam_putenv.c

    r648 r913  
    5959{
    6060        char **env, *p;
     61        size_t env_size;
    6162        int i;
    6263
    6364        ENTER();
    64         if (pamh == NULL)
    65                 RETURNC(PAM_SYSTEM_ERR);
    6665
    6766        /* sanity checks */
    68         if (namevalue == NULL || (p = strchr(namevalue, '=')) == NULL)
     67        if ((p = strchr(namevalue, '=')) == NULL)
    6968                RETURNC(PAM_SYSTEM_ERR);
    7069
     
    8079        /* grow the environment list if necessary */
    8180        if (pamh->env_count == pamh->env_size) {
    82                 env = realloc(pamh->env,
    83                     sizeof(char *) * (pamh->env_size * 2 + 1));
     81                env_size = pamh->env_size * 2 + 1;
     82                env = realloc(pamh->env, sizeof(char *) * env_size);
    8483                if (env == NULL)
    8584                        RETURNC(PAM_BUF_ERR);
    8685                pamh->env = env;
    87                 pamh->env_size = pamh->env_size * 2 + 1;
     86                pamh->env_size = env_size;
    8887        }
    8988
  • trunk/lib/libpam/pam_set_data.c

    r648 r913  
    6565
    6666        ENTERS(module_data_name);
    67         if (pamh == NULL)
    68                 RETURNC(PAM_SYSTEM_ERR);
    6967        for (dp = pamh->module_data; dp != NULL; dp = dp->next) {
    7068                if (strcmp(dp->name, module_data_name) == 0) {
  • trunk/lib/libpam/pam_set_item.c

    r648 r913  
    6565
    6666        ENTERI(item_type);
    67         if (pamh == NULL)
    68                 RETURNC(PAM_SYSTEM_ERR);
    6967        slot = &pamh->item[item_type];
    7068        osize = nsize = 0;
  • trunk/lib/libpam/pam_setenv.c

    r648 r913  
    6666
    6767        ENTER();
    68         if (pamh == NULL)
    69                 RETURNC(PAM_SYSTEM_ERR);
    7068
    7169        /* sanity checks */
    72         if (name == NULL || value == NULL || strchr(name, '=') != NULL)
     70        if (*name == '\0' || strchr(name, '=') != NULL)
    7371                RETURNC(PAM_SYSTEM_ERR);
    7472
Note: See TracChangeset for help on using the changeset viewer.