Ver código fonte

tls: safety check for current cipher

- SSL_get_current_cipher(...) may return NULL, in case of the cipher was
  not set yet for the connection
- caused crash when RPC command tls.list was used in such moment
- cipher description is set to 'unknown' for such case
- reported by Francesco Castellano
Daniel-Constantin Mierla 14 anos atrás
pai
commit
816a021813
1 arquivos alterados com 7 adições e 3 exclusões
  1. 7 3
      modules/tls/tls_rpc.c

+ 7 - 3
modules/tls/tls_rpc.c

@@ -133,11 +133,15 @@ static void tls_list(rpc_t* rpc, void* c)
 					"dst_ip", dst_ip,
 					"dst_ip", dst_ip,
 					"dst_port", con->rcv.dst_port);
 					"dst_port", con->rcv.dst_port);
 			if (tls_d) {
 			if (tls_d) {
-				tls_info = SSL_CIPHER_description(
+				if(SSL_get_current_cipher(tls_d->ssl)) {
+					tls_info = SSL_CIPHER_description(
 									SSL_get_current_cipher(tls_d->ssl),
 									SSL_get_current_cipher(tls_d->ssl),
 									buf, sizeof(buf));
 									buf, sizeof(buf));
-				len = strlen(buf);
-				if (len && buf[len - 1] == '\n') buf[len - 1] = '\0';
+					len = strlen(buf);
+					if (len && buf[len - 1] == '\n') buf[len - 1] = '\0';
+				} else {
+					tls_info = "unknown";
+				}
 				/* tls data */
 				/* tls data */
 				state = "unknown/error";
 				state = "unknown/error";
 				lock_get(&con->write_lock);
 				lock_get(&con->write_lock);