File quiche-absl-HexStringToBytes.patch of Package nodejs-electron-cdm

From a484a561d3d36beca0d4dc9f5d4a2c083be03e1f Mon Sep 17 00:00:00 2001
From: awillia <awillia@google.com>
Date: Tue, 19 Mar 2024 17:22:54 -0700
Subject: [PATCH] Replace deprecated version of absl::HexStringToBytes in test
 programs and remaining quic/ tests

Replaces the deprecated version of absl::HexStringToBytes that returns std::string with the version that returns bool and populates a passed in std::string. This CL isn't expected to change the behavior of any code used in production.

This allows the Chrome build of QUICHE to build without the `-Wno-deprecated-declarations` clang flag.

PiperOrigin-RevId: 617342915
---
 .../web_transport_fingerprint_proof_verifier.cc | 12 ++++++++++--
 quiche/quic/masque/masque_client_bin.cc         |  7 ++++++-
 quiche/quic/masque/masque_server_backend.cc     |  5 ++++-
 quiche/quic/tools/crypto_message_printer_bin.cc |  6 +++++-
 quiche/quic/tools/quic_packet_printer_bin.cc    |  6 +++++-
 quiche/quic/tools/quic_toy_client.cc            | 17 +++++++++--------
 6 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/quiche/quic/core/crypto/web_transport_fingerprint_proof_verifier.cc b/quiche/quic/core/crypto/web_transport_fingerprint_proof_verifier.cc
index 167e4efc4..fc8cffd40 100644
--- a/net/third_party/quiche/src/quiche/quic/core/crypto/web_transport_fingerprint_proof_verifier.cc
+++ b/net/third_party/quiche/src/quiche/quic/core/crypto/web_transport_fingerprint_proof_verifier.cc
@@ -18,6 +20,7 @@
 #include "quiche/quic/core/quic_types.h"
 #include "quiche/quic/core/quic_utils.h"
 #include "quiche/quic/platform/api/quic_bug_tracker.h"
+#include "quiche/quic/platform/api/quic_logging.h"
 #include "quiche/common/quiche_text_utils.h"
 
 namespace quic {
@@ -83,8 +86,13 @@ bool WebTransportFingerprintProofVerifier::AddFingerprint(
 
   std::string normalized =
       absl::StrReplaceAll(fingerprint.fingerprint, {{":", ""}});
-  hashes_.push_back(WebTransportHash{fingerprint.algorithm,
-                                     absl::HexStringToBytes(normalized)});
+  std::string normalized_bytes;
+  if (!absl::HexStringToBytes(normalized, &normalized_bytes)) {
+    QUIC_DLOG(WARNING) << "Fingerprint hexadecimal is invalid";
+    return false;
+  }
+  hashes_.push_back(
+      WebTransportHash{fingerprint.algorithm, std::move(normalized_bytes)});
   return true;
 }
 
diff --git a/quiche/quic/masque/masque_client_bin.cc b/quiche/quic/masque/masque_client_bin.cc
index eefd002dc..06e6ed2b7 100644
--- a/net/third_party/quiche/src/quiche/quic/masque/masque_client_bin.cc
+++ b/net/third_party/quiche/src/quiche/quic/masque/masque_client_bin.cc
@@ -281,7 +281,12 @@ int RunMasqueClient(int argc, char* argv[]) {
         QUIC_LOG(ERROR) << "Concealed authentication key ID cannot be empty";
         return 1;
       }
-      private_key_seed = absl::HexStringToBytes(concealed_auth_param_split[1]);
+      if (!absl::HexStringToBytes(concealed_auth_param_split[1],
+                                  &private_key_seed)) {
+        QUIC_LOG(ERROR) << "Concealed authentication key hex value is invalid";
+        return 1;
+      }
+
       if (private_key_seed.size() != kEd25519Rfc8032PrivateKeySize) {
         QUIC_LOG(ERROR)
             << "Invalid Concealed authentication private key length "
diff --git a/quiche/quic/masque/masque_server_backend.cc b/quiche/quic/masque/masque_server_backend.cc
index f4ff2e0ed..66ca13c96 100644
--- a/net/third_party/quiche/src/quiche/quic/masque/masque_server_backend.cc
+++ b/net/third_party/quiche/src/quiche/quic/masque/masque_server_backend.cc
@@ -193,7 +193,10 @@ void MasqueServerBackend::SetSignatureAuth(absl::string_view signature_auth) {
     quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace(&kv[1]);
     ConcealedAuthCredential credential;
     credential.key_id = std::string(kv[0]);
-    std::string public_key = absl::HexStringToBytes(kv[1]);
+    std::string public_key;
+    if (!absl::HexStringToBytes(kv[1], &public_key)) {
+      QUIC_LOG(FATAL) << "Invalid concealed auth public key hex " << kv[1];
+    }
     if (public_key.size() != sizeof(credential.public_key)) {
       QUIC_LOG(FATAL) << "Invalid concealed auth public key length "
                       << public_key.size();
diff --git a/quiche/quic/tools/crypto_message_printer_bin.cc b/quiche/quic/tools/crypto_message_printer_bin.cc
index eb7393d54..82850d94a 100644
--- a/net/third_party/quiche/src/quiche/quic/tools/crypto_message_printer_bin.cc
+++ b/net/third_party/quiche/src/quiche/quic/tools/crypto_message_printer_bin.cc
@@ -48,7 +48,11 @@ int main(int argc, char* argv[]) {
   quic::CryptoFramer framer;
   framer.set_visitor(&printer);
   framer.set_process_truncated_messages(true);
-  std::string input = absl::HexStringToBytes(messages[0]);
+  std::string input;
+  if (!absl::HexStringToBytes(messages[0], &input)) {
+    cerr << "Invalid hex string provided" << endl;
+    return 1;
+  }
   if (!framer.ProcessInput(input)) {
     return 1;
   }
diff --git a/quiche/quic/tools/quic_packet_printer_bin.cc b/quiche/quic/tools/quic_packet_printer_bin.cc
index 5ed77010a..314cc20ea 100644
--- a/net/third_party/quiche/src/quiche/quic/tools/quic_packet_printer_bin.cc
+++ b/net/third_party/quiche/src/quiche/quic/tools/quic_packet_printer_bin.cc
@@ -270,7 +270,11 @@ int main(int argc, char* argv[]) {
     quiche::QuichePrintCommandLineFlagHelp(usage);
     return 1;
   }
-  std::string hex = absl::HexStringToBytes(args[1]);
+  std::string hex;
+  if (!absl::HexStringToBytes(args[1], &hex)) {
+    std::cerr << "Invalid hex string" << std::endl;
+    return 1;
+  }
   quic::ParsedQuicVersionVector versions = quic::AllSupportedVersions();
   // Fake a time since we're not actually generating acks.
   quic::QuicTime start(quic::QuicTime::Zero());
openSUSE Build Service is sponsored by