Blob Blame History Raw
From 027596a3df85d11948f4fb3a28d27d6523645589 Mon Sep 17 00:00:00 2001
From: Alexander Scheel <alexander.m.scheel@gmail.com>
Date: Thu, 14 Sep 2017 11:24:39 -0500
Subject: [PATCH] Fix error handling in gpm_send_buffer/gpm_recv_buffer

Signed-off-by: Alexander Scheel <alexander.m.scheel@gmail.com>
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
Merges: #213
[rharwood@redhat.com: commit message formatting, copyright update]
(cherry picked from commit f2530fc280dd84e6abc0f5475e261aa0d2ee2a21)
---
 proxy/src/client/gpm_common.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c
index b14e846..0d314fa 100644
--- a/proxy/src/client/gpm_common.c
+++ b/proxy/src/client/gpm_common.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 the GSS-PROXY contributors, see COPYING for license */
+/* Copyright (C) 2011,2017 the GSS-PROXY contributors, see COPYING for license */
 
 #include "gssapi_gpm.h"
 #include <sys/types.h>
@@ -415,10 +415,7 @@ static int gpm_send_buffer(struct gpm_ctx *gpmctx,
     ret = 0;
 
 done:
-    if (ret) {
-        /* on errors we can only close the fd and return */
-        gpm_close_socket(gpmctx);
-    }
+    /* we only need to return as gpm_retry_socket closes the socket */
     return ret;
 }
 
@@ -488,9 +485,10 @@ static int gpm_recv_buffer(struct gpm_ctx *gpmctx,
 
 done:
     if (ret) {
-        /* on errors we can only close the fd and return */
-        gpm_close_socket(gpmctx);
-        gpm_epoll_close(gpmctx);
+        /* on errors, free the buffer to prevent calling
+         * xdr_destroy(&xdr_reply_ctx); */
+        free(*buffer);
+        *buffer = NULL;
     }
     return ret;
 }
@@ -560,10 +558,6 @@ static int gpm_send_recv_loop(struct gpm_ctx *gpmctx, char *send_buffer,
             /* Close and reopen socket before trying again */
             ret = gpm_retry_socket(gpmctx);
 
-            /* Free buffer and set it to NULL to prevent free(xdr_reply_ctx) */
-            free(*recv_buffer);
-            *recv_buffer = NULL;
-
             if (ret != 0)
                 return ret;
             ret = ETIMEDOUT;