Blame SOURCES/0039-pam_sss_gssapi-fix-coverity-issues.patch

c5e826
From 111b8b4d62a4fe192c075e6f6bfacb408e6074b3 Mon Sep 17 00:00:00 2001
c5e826
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
c5e826
Date: Tue, 12 Jan 2021 13:50:11 +0100
c5e826
Subject: [PATCH 39/39] pam_sss_gssapi: fix coverity issues
c5e826
MIME-Version: 1.0
c5e826
Content-Type: text/plain; charset=UTF-8
c5e826
Content-Transfer-Encoding: 8bit
c5e826
c5e826
```
c5e826
1. Defect type: RESOURCE_LEAK
c5e826
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:556: leaked_storage: Variable "username" going out of scope leaks the storage it points to.
c5e826
Expand
c5e826
2. Defect type: RESOURCE_LEAK
c5e826
3. sssd-2.4.0/src/sss_client/pam_sss_gss.c:321: leaked_storage: Variable "reply" going out of scope leaks the storage it points to.
c5e826
Expand
c5e826
3. Defect type: RESOURCE_LEAK
c5e826
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "username" going out of scope leaks the storage it points to.
c5e826
Expand
c5e826
4. Defect type: RESOURCE_LEAK
c5e826
6. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "upn" going out of scope leaks the storage it points to.
c5e826
Expand
c5e826
5. Defect type: RESOURCE_LEAK
c5e826
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "target" going out of scope leaks the storage it points to.
c5e826
Expand
c5e826
6. Defect type: RESOURCE_LEAK
c5e826
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "domain" going out of scope leaks the storage it points to.
c5e826
c5e826
1. Defect type: CLANG_WARNING
c5e826
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'username'
c5e826
Expand
c5e826
2. Defect type: CLANG_WARNING
c5e826
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'upn'
c5e826
Expand
c5e826
3. Defect type: CLANG_WARNING
c5e826
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'target'
c5e826
Expand
c5e826
4. Defect type: CLANG_WARNING
c5e826
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'domain'
c5e826
```
c5e826
c5e826
Also fix compilation warning
c5e826
```
c5e826
../src/sss_client/pam_sss_gss.c:339:5: warning: ‘reply’ may be used uninitialized in this function [-Wmaybe-uninitialized]
c5e826
  339 |     free(reply);
c5e826
      |     ^~~~~~~~~~~
c5e826
../src/sss_client/pam_sss_gss.c:328:14: note: ‘reply’ was declared here
c5e826
  328 |     uint8_t *reply;
c5e826
      |              ^~~~~
c5e826
../src/sss_client/pam_sss_gss.c:270:11: warning: ‘reply_len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
c5e826
  270 |     upn = malloc(reply_len * sizeof(char));
c5e826
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c5e826
../src/sss_client/pam_sss_gss.c:327:12: note: ‘reply_len’ was declared here
c5e826
  327 |     size_t reply_len;
c5e826
      |            ^~~~~~~~~
c5e826
```
c5e826
c5e826
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
c5e826
Reviewed-by: Sumit Bose <sbose@redhat.com>
c5e826
---
c5e826
 src/sss_client/pam_sss_gss.c | 22 ++++++++++++++++++----
c5e826
 1 file changed, 18 insertions(+), 4 deletions(-)
c5e826
c5e826
diff --git a/src/sss_client/pam_sss_gss.c b/src/sss_client/pam_sss_gss.c
c5e826
index cd38db7da..51be36ece 100644
c5e826
--- a/src/sss_client/pam_sss_gss.c
c5e826
+++ b/src/sss_client/pam_sss_gss.c
c5e826
@@ -195,6 +195,8 @@ static errno_t sssd_gssapi_init_send(pam_handle_t *pamh,
c5e826
     struct sss_cli_req_data req_data;
c5e826
     size_t service_len;
c5e826
     size_t user_len;
c5e826
+    size_t reply_len;
c5e826
+    uint8_t *reply = NULL;
c5e826
     uint8_t *data;
c5e826
     errno_t ret;
c5e826
     int ret_errno;
c5e826
@@ -217,7 +219,7 @@ static errno_t sssd_gssapi_init_send(pam_handle_t *pamh,
c5e826
 
c5e826
     req_data.data = data;
c5e826
 
c5e826
-    ret = sss_pam_make_request(SSS_GSSAPI_INIT, &req_data, _reply, _reply_len,
c5e826
+    ret = sss_pam_make_request(SSS_GSSAPI_INIT, &req_data, &reply, &reply_len,
c5e826
                                &ret_errno);
c5e826
     free(data);
c5e826
     if (ret != PAM_SUCCESS) {
c5e826
@@ -233,6 +235,16 @@ static errno_t sssd_gssapi_init_send(pam_handle_t *pamh,
c5e826
         return (ret_errno != EOK) ? ret_errno : EIO;
c5e826
     }
c5e826
 
c5e826
+    if (ret_errno == EOK) {
c5e826
+        *_reply = reply;
c5e826
+        *_reply_len = reply_len;
c5e826
+    } else {
c5e826
+        /* We got PAM_SUCCESS therefore the communication with SSSD was
c5e826
+         * successful and we have received a reply buffer. We just don't care
c5e826
+         * about it, we are only interested in the error code. */
c5e826
+        free(reply);
c5e826
+    }
c5e826
+
c5e826
     return ret_errno;
c5e826
 }
c5e826
 
c5e826
@@ -257,7 +269,8 @@ static errno_t sssd_gssapi_init_recv(uint8_t *reply,
c5e826
     target = malloc(reply_len * sizeof(char));
c5e826
     upn = malloc(reply_len * sizeof(char));
c5e826
     if (username == NULL || domain == NULL || target == NULL || upn == NULL) {
c5e826
-        return ENOMEM;
c5e826
+        ret = ENOMEM;
c5e826
+        goto done;
c5e826
     }
c5e826
 
c5e826
     buf = (const char*)reply;
c5e826
@@ -311,8 +324,8 @@ static errno_t sssd_gssapi_init(pam_handle_t *pamh,
c5e826
                                 char **_target,
c5e826
                                 char **_upn)
c5e826
 {
c5e826
-    size_t reply_len;
c5e826
-    uint8_t *reply;
c5e826
+    size_t reply_len = 0;
c5e826
+    uint8_t *reply = NULL;
c5e826
     errno_t ret;
c5e826
 
c5e826
     ret = sssd_gssapi_init_send(pamh, pam_service, pam_user, &reply,
c5e826
@@ -549,6 +562,7 @@ int pam_sm_authenticate(pam_handle_t *pamh,
c5e826
 
c5e826
 done:
c5e826
     sss_pam_close_fd();
c5e826
+    free(username);
c5e826
     free(domain);
c5e826
     free(target);
c5e826
     free(upn);
c5e826
-- 
c5e826
2.21.3
c5e826