Copilot commented on code in PR #13397:
URL: https://github.com/apache/trafficserver/pull/13397#discussion_r3708541107
##########
src/iocore/net/quic/QUICConfig.cc:
##########
@@ -23,23 +23,158 @@
#include "iocore/net/quic/QUICConfig.h"
+#include <openssl/crypto.h>
+#include <openssl/rand.h>
#if TS_HAS_OPENSSL_QUIC
#include <openssl/quic.h>
#endif
#include <openssl/ssl.h>
#include "mgmt/config/ConfigContextDiags.h"
+#include "mgmt/config/ConfigRegistry.h"
#include "records/RecHttp.h"
+#include "tscore/Layout.h"
+#include "tscore/MatcherUtils.h"
+#include "tscore/ink_memory.h"
#include "../P_SSLConfig.h"
#include "../P_TLSKeyLogger.h"
#include "iocore/net/quic/QUICGlobals.h"
#include "iocore/net/quic/QUICTransportParameters.h"
+int QUICTokenKeyConfig::_config_id = 0;
int QUICConfig::_config_id = 0;
int QUICConfigParams::_connection_table_size = 65521;
+QUICTokenKeyConfigParams::~QUICTokenKeyConfigParams()
+{
+ if (!m_keys.empty()) {
+ OPENSSL_cleanse(m_keys.data(), m_keys.size() * sizeof(Key));
+ }
+}
+
+bool
+QUICTokenKeyConfigParams::load(const char *path, ConfigContext ctx)
+{
+ int key_data_len = 0;
+ ats_scoped_str key_data{readIntoBuffer(path, __func__, &key_data_len)};
+
+ if (!key_data) {
+ CfgLoadFail(ctx, "Could not load QUIC token key from %s", path);
+ return false;
+ }
+
+ if (key_data_len < static_cast<int>(KEY_LENGTH) || key_data_len % KEY_LENGTH
!= 0) {
+ CfgLoadFail(ctx, "QUIC token key file %s must contain one or more %zu-byte
keys", path, KEY_LENGTH);
+ OPENSSL_cleanse(key_data.get(), key_data_len);
+ return false;
+ }
+
+ m_keys.resize(key_data_len / KEY_LENGTH);
+ memcpy(m_keys.data(), key_data.get(), key_data_len);
+ OPENSSL_cleanse(key_data.get(), key_data_len);
+ m_filename = path;
+ return true;
Review Comment:
`readIntoBuffer()` reports the byte count via an `int*`. If the file is
larger than `INT_MAX`, that value can overflow to a negative number; the
current code then uses `key_data_len` as the length for `OPENSSL_cleanse()` and
`memcpy()`, which will be converted to a huge `size_t` and can crash or corrupt
memory. Guard against negative lengths and use a `size_t` for subsequent size
calculations/cleansing/copies.
--
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]