summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-07-30 21:08:16 +0800
committeryangwei <[email protected]>2023-07-30 21:22:08 +0800
commit2691a1ea21267f6ca247882f0a38ae285c32945a (patch)
treea0ece55a13b47923e957590c4deceb12426d62d5
parent41c94038e9fc044c7560fecea859571a03301b64 (diff)
🐞 fix(parse_extensions): 判断sni和alpn的已解析结果,避免出现多个时的内存泄漏
-rw-r--r--src/tsg_ssl_utils.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/tsg_ssl_utils.cpp b/src/tsg_ssl_utils.cpp
index 86fd8d2..96ff144 100644
--- a/src/tsg_ssl_utils.cpp
+++ b/src/tsg_ssl_utils.cpp
@@ -205,6 +205,7 @@ static char* parse_server_name_extension(const unsigned char* buff, size_t buff
static enum chello_parse_result parse_extensions(const unsigned char* buff, size_t buff_len, struct ssl_chello* chello) {
size_t pos = 0;
+ char *p_buff=NULL;
/* Parse each 4 bytes for the extension header */
while (pos + 4 <= buff_len)
{
@@ -217,7 +218,16 @@ static enum chello_parse_result parse_extensions(const unsigned char* buff, size
return CHELLO_PARSE_INVALID_FORMAT;
}
enum chello_parse_result result = CHELLO_PARSE_SUCCESS;
- chello->sni = parse_server_name_extension(buff + pos + 4, len, &result);
+ p_buff=parse_server_name_extension(buff + pos + 4, len, &result);
+ if(chello->sni == NULL)
+ {
+ chello->sni = p_buff;
+ }
+ else
+ {
+ free(p_buff);
+ p_buff=NULL;
+ }
if(result != CHELLO_PARSE_SUCCESS)
{
return result;
@@ -231,7 +241,16 @@ static enum chello_parse_result parse_extensions(const unsigned char* buff, size
return CHELLO_PARSE_INVALID_FORMAT;
}
enum chello_parse_result result = CHELLO_PARSE_SUCCESS;
- chello->alpn = parse_alpn_extension(buff + pos + 4, len, &result);
+ p_buff = parse_alpn_extension(buff + pos + 4, len, &result);
+ if(chello->alpn == NULL)
+ {
+ chello->alpn = p_buff;
+ }
+ else
+ {
+ free(p_buff);
+ p_buff=NULL;
+ }
if(result != CHELLO_PARSE_SUCCESS)
{
return result;