trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [trafficserver] 06/07: fix stringstream crash during shutdown
Date Tue, 10 Dec 2019 23:02:32 GMT
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 29134f54955b51d88a13a92a5991912cd07e4008
Author: Fei Deng <duke8253@gmail.com>
AuthorDate: Wed Nov 20 15:44:40 2019 -0600

    fix stringstream crash during shutdown
    
    (cherry picked from commit bed0184bb12be5d58e10ae7aefc589d458b2d83b)
---
 .../experimental/ssl_session_reuse/src/common.cc    | 21 ++++++++++++---------
 plugins/experimental/ssl_session_reuse/src/common.h |  3 +--
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/plugins/experimental/ssl_session_reuse/src/common.cc b/plugins/experimental/ssl_session_reuse/src/common.cc
index e552c5a..581f6f9 100644
--- a/plugins/experimental/ssl_session_reuse/src/common.cc
+++ b/plugins/experimental/ssl_session_reuse/src/common.cc
@@ -30,18 +30,21 @@
 
 #include "common.h"
 
-const unsigned char salt[] = {115, 97, 108, 117, 0, 85, 137, 229};
+const unsigned char salt[]      = {115, 97, 108, 117, 0, 85, 137, 229};
+const unsigned char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
'B', 'C', 'D', 'E', 'F'};
 
 std::string
-hex_str(std::string str)
+hex_str(std::string const &str)
 {
-  std::string hex_str = "";
-  for (char &c : str) {
-    std::stringstream stream;
-    stream << std::hex << std::setfill('0') << std::setw(2) << (0xFF
& static_cast<unsigned int>(c));
-    hex_str += stream.str();
-  }
-  return hex_str;
+  size_t len = str.size() * 2 + 1;
+  char hex_str[len];
+  for (unsigned long int i = 0; i < str.size(); ++i) {
+    unsigned char c    = str.at(i);
+    hex_str[i * 2]     = hex_chars[(c & 0xF0) >> 4];
+    hex_str[i * 2 + 1] = hex_chars[(c & 0x0F)];
+  }
+  hex_str[len] = '\0';
+  return std::string(hex_str, len);
 }
 
 int
diff --git a/plugins/experimental/ssl_session_reuse/src/common.h b/plugins/experimental/ssl_session_reuse/src/common.h
index bcec00b..377d9fc 100644
--- a/plugins/experimental/ssl_session_reuse/src/common.h
+++ b/plugins/experimental/ssl_session_reuse/src/common.h
@@ -24,7 +24,6 @@
 #pragma once
 
 #include <iostream>
-#include <sstream>
 #include <iomanip>
 #include <string>
 #include <cstring>
@@ -70,7 +69,7 @@ private:
   std::mutex threads_mutex;
 };
 
-std::string hex_str(std::string str);
+std::string hex_str(std::string const &str);
 
 int encrypt_encode64(const unsigned char *key, int key_length, const unsigned char *in_data,
int in_data_len, char *out_data,
                      size_t out_data_size, size_t *out_data_len);


Mime
View raw message