mirror of
https://github.com/esphome/esphome.git
synced 2026-09-20 19:48:39 +00:00
Use fixed stack buffer for query strings bounded by CONFIG_HTTPD_MAX_URI_LEN
Query strings cannot exceed the max URI length, so SmallBufferWithHeapFallback is unnecessary. Use a plain stack array instead for zero heap allocation.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#ifdef USE_ESP32
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include "esphome/core/helpers.h"
|
||||
@@ -56,15 +55,13 @@ optional<std::string> query_key_value(const char *query_url, size_t query_len, c
|
||||
return {};
|
||||
}
|
||||
|
||||
// Use stack buffer for typical query strings, heap fallback for large ones
|
||||
SmallBufferWithHeapFallback<256, char> val(query_len);
|
||||
|
||||
if (httpd_query_key_value(query_url, key, val.get(), query_len) != ESP_OK) {
|
||||
char val[CONFIG_HTTPD_MAX_URI_LEN + 1];
|
||||
if (httpd_query_key_value(query_url, key, val, query_len) != ESP_OK) {
|
||||
return {};
|
||||
}
|
||||
|
||||
url_decode(val.get());
|
||||
return {val.get()};
|
||||
url_decode(val);
|
||||
return {val};
|
||||
}
|
||||
|
||||
bool query_has_key(const char *query_url, size_t query_len, const char *key) {
|
||||
|
||||
@@ -422,11 +422,11 @@ static auto search_query_sources(httpd_req_t *req, const std::string &post_query
|
||||
if (len == 0) {
|
||||
return {};
|
||||
}
|
||||
SmallBufferWithHeapFallback<256, char> buf(len + 1);
|
||||
if (httpd_req_get_url_query_str(req, buf.get(), len + 1) != ESP_OK) {
|
||||
char buf[AsyncWebServerRequest::URL_BUF_SIZE];
|
||||
if (httpd_req_get_url_query_str(req, buf, len + 1) != ESP_OK) {
|
||||
return {};
|
||||
}
|
||||
return func(buf.get(), len, name);
|
||||
return func(buf, len, name);
|
||||
}
|
||||
|
||||
optional<std::string> AsyncWebServerRequest::find_query_value_(const char *name) const {
|
||||
|
||||
Reference in New Issue
Block a user