[SSSD] [PATCH] PAM: Test return value of strdup

Lukas Slebodnik lslebodn at redhat.com
Fri Mar 7 12:40:34 UTC 2014


ehlo,

Warnings reported by Coverity (12463,12464)

Dereferencing a pointer that might be null pi->pam_authtok when calling strlen.
Dereferencing a pointer that might be null action when calling strncmp.

Patch is attached.

LS
-------------- next part --------------
>From 503d94290421c7c20aab221bfc64300d61e90530 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Fri, 7 Mar 2014 09:26:22 +0100
Subject: [PATCH] PAM: Test return value of strdup

Warnings reported by Coverity (12463,12464)

Dereferencing a pointer that might be null pi->pam_authtok when calling strlen.
Dereferencing a pointer that might be null action when calling strncmp.
---
 src/sss_client/pam_sss.c         | 4 ++++
 src/sss_client/pam_test_client.c | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/src/sss_client/pam_sss.c b/src/sss_client/pam_sss.c
index 638e211eea01d1f851201c34d95f57189645ea50..d45b2e88f16b030b81b180cef233bc024347f5d8 100644
--- a/src/sss_client/pam_sss.c
+++ b/src/sss_client/pam_sss.c
@@ -1368,6 +1368,10 @@ static int get_authtok_for_password_change(pam_handle_t *pamh,
         }
     } else {
         pi->pam_authtok = strdup(pi->pamstack_oldauthtok);
+        if (pi->pam_authtok == NULL) {
+            D(("strdup failed"));
+            return PAM_BUF_ERR;
+        }
         pi->pam_authtok_type = SSS_AUTHTOK_TYPE_PASSWORD;
         pi->pam_authtok_size = strlen(pi->pam_authtok);
     }
diff --git a/src/sss_client/pam_test_client.c b/src/sss_client/pam_test_client.c
index ef424e77c7fbfd837f55cc889ceb015c3bb191ef..af8a0da9090a755041ed968b6ec60ae81bacf142 100644
--- a/src/sss_client/pam_test_client.c
+++ b/src/sss_client/pam_test_client.c
@@ -53,6 +53,11 @@ int main(int argc, char *argv[]) {
         user = strdup(argv[2]);
     }
 
+    if (action == NULL || user == NULL) {
+        fprintf(stderr, "Out of memory!\n");
+        return 1;
+    }
+
     fprintf(stdout, "action: %s\nuser: %s\n", action,user);
 
     ret = pam_start("sss_test", user, &conv, &pamh);
-- 
1.8.5.3



More information about the sssd-devel mailing list