gavinchou commented on code in PR #55241:
URL: https://github.com/apache/doris/pull/55241#discussion_r2305987914
##########
cloud/src/meta-service/meta_service_helper.h:
##########
@@ -61,36 +61,82 @@ inline std::string md5(const std::string& str) {
* - Input string contains one or more occurrences of "sk: " followed by a
value in double quotes.
* - An md5() function exists that takes a std::string and returns its MD5
hash as a string.
*
- * @param debug_string Input string containing "sk: " fields to be encrypted.
+ * @param debug_string Input string containing "sk: " or ""sk": " fields to be
encrypted.
* @return A new string with all "sk" values replaced by their MD5 hashes.
*
- * Behavior:
+ * Behavior for "sk: " format:
* 1. Searches for all occurrences of "sk: " in the input string.
* 2. For each occurrence, extracts the value between double quotes.
* 3. Replaces the original value with "md5: " followed by its MD5 hash.
* 4. Returns the modified string with all "sk" values encrypted.
*/
inline std::string encryt_sk(std::string debug_string) {
- // Start position for searching "sk" fields
- size_t pos = 0;
- // Iterate through the string and find all occurrences of "sk: "
- while ((pos = debug_string.find("sk: ", pos)) != std::string::npos) {
- // Find the start and end of the "sk" value (assumed to be within
quotes)
- // Start after the quote
- size_t sk_value_start = debug_string.find('\"', pos) + 1;
- // End at the next quote
- size_t sk_value_end = debug_string.find('\"', sk_value_start);
-
- // Extract the "sk" value
- std::string sk_value = debug_string.substr(sk_value_start,
sk_value_end - sk_value_start);
- // Encrypt the "sk" value with MD5
+ auto replace_sk_with_value = [&debug_string](size_t value_start, size_t
value_end) {
+ // Extract and encrypt the sk value
+ std::string sk_value = debug_string.substr(value_start, value_end -
value_start);
std::string encrypted_sk = "md5: " + md5(sk_value);
- // Replace the original "sk" value with the encrypted MD5 value
- debug_string.replace(sk_value_start, sk_value_end - sk_value_start,
encrypted_sk);
- // Move the position to the end of the current "sk" field and continue
searching
- pos = sk_value_end;
+ // Replace the original value with encrypted version
+ debug_string.replace(value_start, value_end - value_start,
encrypted_sk);
+
+ // Return the position adjustment for next search
+ return encrypted_sk.length() - sk_value.length();
+ };
+
+ // Process format: "sk: \"value\""
+ {
+ const std::string pattern = "sk: ";
+ size_t pos = 0;
+ while ((pos = debug_string.find(pattern, pos)) != std::string::npos) {
+ // Find the value quotes
+ size_t quote_pos = debug_string.find('\"', pos);
+ if (quote_pos == std::string::npos) {
+ pos += pattern.length();
+ continue;
+ }
+
+ size_t value_start = quote_pos + 1;
+ size_t value_end = debug_string.find('\"', value_start);
+ if (value_end == std::string::npos) {
+ pos = value_start;
+ continue;
+ }
+
+ int pos_adjustment = replace_sk_with_value(value_start, value_end);
+ pos = value_end + pos_adjustment;
+ }
+ }
+
+ // Process format: "\"sk\": \"value\""
+ {
+ const std::string pattern = "\"sk\"";
Review Comment:
<img width="792" height="726" alt="image"
src="https://github.com/user-attachments/assets/1e0bc32b-76b6-47b3-96a8-935ae213389a"
/>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]