Skip to content

Commit 133d78b

Browse files
committed
Added checks for negative indexes
1 parent 81fb455 commit 133d78b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/ESPAsyncWebServer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class AsyncWebServerRequest {
541541
*/
542542
const AsyncWebParameter *getParam(size_t num) const;
543543
const AsyncWebParameter *getParam(int num) const {
544-
return getParam((size_t)num);
544+
return num < 0 ? nullptr : getParam((size_t)num);
545545
}
546546

547547
size_t args() const {
@@ -559,11 +559,11 @@ class AsyncWebServerRequest {
559559
#endif
560560
const String &arg(size_t i) const; // get request argument value by number
561561
const String &arg(int i) const {
562-
return arg((size_t)i);
562+
return i < 0 ? emptyString : arg((size_t)i);
563563
};
564564
const String &argName(size_t i) const; // get request argument name by number
565565
const String &argName(int i) const {
566-
return argName((size_t)i);
566+
return i < 0 ? emptyString : argName((size_t)i);
567567
};
568568
bool hasArg(const char *name) const; // check if argument exists
569569
bool hasArg(const String &name) const {
@@ -575,7 +575,7 @@ class AsyncWebServerRequest {
575575

576576
const String &ASYNCWEBSERVER_REGEX_ATTRIBUTE pathArg(size_t i) const;
577577
const String &ASYNCWEBSERVER_REGEX_ATTRIBUTE pathArg(int i) const {
578-
return pathArg((size_t)i);
578+
return i < 0 ? emptyString : pathArg((size_t)i);
579579
}
580580

581581
// get request header value by name
@@ -590,11 +590,11 @@ class AsyncWebServerRequest {
590590

591591
const String &header(size_t i) const; // get request header value by number
592592
const String &header(int i) const {
593-
return header((size_t)i);
593+
return i < 0 ? emptyString : header((size_t)i);
594594
};
595595
const String &headerName(size_t i) const; // get request header name by number
596596
const String &headerName(int i) const {
597-
return headerName((size_t)i);
597+
return i < 0 ? emptyString : headerName((size_t)i);
598598
};
599599

600600
size_t headers() const; // get header count
@@ -618,7 +618,7 @@ class AsyncWebServerRequest {
618618

619619
const AsyncWebHeader *getHeader(size_t num) const;
620620
const AsyncWebHeader *getHeader(int num) const {
621-
return getHeader((size_t)num);
621+
return num < 0 ? nullptr : getHeader((size_t)num);
622622
};
623623

624624
const std::list<AsyncWebHeader> &getHeaders() const {

0 commit comments

Comments
 (0)