buffer underflow bug fixed (in error handling routines)
authorMarcel Poul <marcel.poul@cern.ch>
Sat, 30 Jun 2012 13:43:45 +0000 (13:43 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Sat, 30 Jun 2012 13:43:45 +0000 (13:43 +0000)
emi.canl.canl-c/src/canl_err.c
emi.canl.canl-c/src/canl_ssl.c

index 737932d..e688528 100644 (file)
@@ -7,7 +7,7 @@ static canl_err_code resolve_error_code(glb_ctx *cc, unsigned long err_code,
 static void get_error_string(glb_ctx *cc, char *code_str);
 static canl_err_code update_error_msg(canl_ctx cc, const char *new_msg);
 static char *canl_strerror(const canl_err_code c_code);
-static canl_error canl_err_ssl_to_canl(const unsigned long ossl_lib,
+static int canl_err_ssl_to_canl(const unsigned long ossl_lib,
         const unsigned long ossl_reason);
 
 /* Save error message into err_msg
@@ -211,11 +211,11 @@ canl_strerror(const canl_err_code c_code)
 
 /*return appropriate CANL_ERROR according to openssl error code or -1 if
 no one found */
-static canl_error
+static int
 canl_err_ssl_to_canl(const unsigned long ossl_lib,
         const unsigned long ossl_reason)
 {
-    canl_error ret_err = -1;
+    int ret_err = -1;
     int k = 0;
     for (k = 0; k < canl_err_descs_num; k++) {
         if (canl_err_descs[k].openssl_lib == ossl_lib) {
@@ -254,6 +254,7 @@ canl_get_error_message(canl_ctx cc)
 static canl_err_code resolve_error_code(glb_ctx *cc, unsigned long err_code, 
         canl_err_origin err_orig)
 {
+    int ret = 0;
     cc->original_err_code = err_code;
     cc->err_orig = err_orig;
 
@@ -268,8 +269,9 @@ static canl_err_code resolve_error_code(glb_ctx *cc, unsigned long err_code,
             break;
         case SSL_ERROR:
             /* TODO What about CANL_ERR_GeneralSSLError ?*/
-            if ((cc->err_code = canl_err_ssl_to_canl(ERR_GET_LIB(err_code),
+            if ((ret = canl_err_ssl_to_canl(ERR_GET_LIB(err_code),
                             ERR_GET_REASON(err_code))) != -1){
+                cc->err_code = ret;
                 cc->err_orig = CANL_ERROR;
             }
             cc->err_code = err_code;
index 2143338..9a6d7fd 100644 (file)
@@ -772,7 +772,6 @@ static int do_ssl_connect(glb_ctx *cc, io_handler *io,
     time_t starttime, curtime;
     int ret = -1, ret2 = -1;
     unsigned long ssl_err = 0;
-    int err = 0;
     canl_err_origin e_orig = UNKNOWN_ERROR;
     long errorcode = 0;
     int expected = 0;
@@ -805,17 +804,18 @@ static int do_ssl_connect(glb_ctx *cc, io_handler *io,
         if (timeout && (curtime - starttime >= locl_timeout)){
             timeout->tv_sec=0;
             timeout->tv_usec=0;
-            err = ETIMEDOUT; 
-            update_error (cc, err, POSIX_ERROR, "Connection stuck during"
+            update_error (cc, ETIMEDOUT, POSIX_ERROR, "Connection stuck during"
                   " handshake: timeout reached");
         }
         else if (ret2 < 0 && ssl_err)
-            return update_error(cc, ssl_err, e_orig, "Error during SSL handshake");
+            update_error(cc, ssl_err, e_orig, "Error during SSL handshake");
         else if (ret2 == 0)//TODO is 0 (conn closed by the other side) error?
             update_error (cc, ECONNREFUSED, POSIX_ERROR, "Connection closed"
                     " by the other side");
         else
-            update_error (cc, err, UNKNOWN_ERROR, "Error during SSL handshake");
+            /*ret2 < 0 && !ssl_err*/
+            update_error (cc, 0, UNKNOWN_ERROR, "Error during SSL handshake"
+                    " in communication with the server");
         return 1;
     }
     return 0;
@@ -827,7 +827,6 @@ static int do_ssl_accept(glb_ctx *cc, io_handler *io,
     time_t starttime, curtime;
     int ret = -1, ret2 = -1;
     unsigned long ssl_err = 0;
-    int err = 0;
     long errorcode = 0;
     int expected = 0;
     int locl_timeout = -1;
@@ -876,8 +875,7 @@ timeout->tv_sec = timeout->tv_sec - (curtime - starttime);
         if (timeout && (curtime - starttime >= locl_timeout)){
             timeout->tv_sec=0;
             timeout->tv_usec=0;
-            err = ETIMEDOUT;
-            set_error (cc, err, POSIX_ERROR, "Connection stuck"
+            set_error (cc, ETIMEDOUT, POSIX_ERROR, "Connection stuck"
                     " during handshake: timeout reached"); 
         }
         else if (ret2 == 0)
@@ -886,7 +884,9 @@ timeout->tv_sec = timeout->tv_sec - (curtime - starttime);
         else if (ret2 < 0 && ssl_err)
             set_error (cc, ssl_err, SSL_ERROR, "Error during SSL handshake");
        else
-           set_error (cc, 0, UNKNOWN_ERROR, "Error during SSL handshake");
+            /*ret2 < 0 && !ssl_err*/
+            set_error (cc, 0, UNKNOWN_ERROR, "Error during SSL handshake"
+                    " in communication with the server");
         return 1;
     }
     return 0;