diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2024-01-02 21:19:53 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2024-01-03 17:16:02 +0000 |
commit | 88759de2aa49171703afd70e3b78ccf17ab7ef95 (patch) | |
tree | 9765a4dd52141913e71e421dbefef5130d8bf004 /modules | |
parent | 5f51dcfa6b804025ed002fe06a0534316d471c0c (diff) | |
download | pam-88759de2aa49171703afd70e3b78ccf17ab7ef95.tar.gz pam-88759de2aa49171703afd70e3b78ccf17ab7ef95.tar.bz2 pam-88759de2aa49171703afd70e3b78ccf17ab7ef95.zip |
pam_unix: unify error handling
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pam_unix/support.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/modules/pam_unix/support.c b/modules/pam_unix/support.c index aa7000b3..336742a1 100644 --- a/modules/pam_unix/support.c +++ b/modules/pam_unix/support.c @@ -404,37 +404,37 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, spasswd = strchr(slogin, ':'); if (spasswd == NULL) { - return matched; + goto fail; } *spasswd++ = '\0'; suid = strchr(spasswd, ':'); if (suid == NULL) { - return matched; + goto fail; } *suid++ = '\0'; sgid = strchr(suid, ':'); if (sgid == NULL) { - return matched; + goto fail; } *sgid++ = '\0'; sgecos = strchr(sgid, ':'); if (sgecos == NULL) { - return matched; + goto fail; } *sgecos++ = '\0'; shome = strchr(sgecos, ':'); if (shome == NULL) { - return matched; + goto fail; } *shome++ = '\0'; sshell = strchr(shome, ':'); if (sshell == NULL) { - return matched; + goto fail; } *sshell++ = '\0'; @@ -446,21 +446,17 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, strlen(sshell) + 1; *ret = calloc(retlen, sizeof(char)); if (*ret == NULL) { - return matched; + goto fail; } (*ret)->pw_uid = strtol(suid, &p, 10); if ((strlen(suid) == 0) || (*p != '\0')) { - free(*ret); - *ret = NULL; - return matched; + goto fail; } (*ret)->pw_gid = strtol(sgid, &p, 10); if ((strlen(sgid) == 0) || (*p != '\0')) { - free(*ret); - *ret = NULL; - return matched; + goto fail; } p = ((char*)(*ret)) + sizeof(struct passwd); @@ -478,12 +474,15 @@ int _unix_getpwnam(pam_handle_t *pamh, const char *name, if (pam_set_data(pamh, buf, *ret, _unix_cleanup) != PAM_SUCCESS) { - free(*ret); - *ret = NULL; + goto fail; } } return matched; +fail: + free(*ret); + *ret = NULL; + return matched; } /* |