Skip to content

Commit 9b9c6ea

Browse files
Potential fix for code scanning alert no. 71: Use of potentially dangerous function
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent c6bc9e8 commit 9b9c6ea

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libraries/HTTPClient/src/HTTPClient.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,9 @@ void HTTPClient::setCookie(String date, String headerValue) {
15931593

15941594
// overwrite or delete cookie in/from cookie jar
15951595
time_t now_local = time(NULL);
1596-
time_t now_gmt = mktime(gmtime(&now_local));
1597-
1596+
struct tm tm_gmt;
1597+
gmtime_r(&now_local, &tm_gmt);
1598+
time_t now_gmt = mktime(&tm_gmt);
15981599
bool found = false;
15991600

16001601
for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) {
@@ -1619,8 +1620,9 @@ void HTTPClient::setCookie(String date, String headerValue) {
16191620

16201621
bool HTTPClient::generateCookieString(String *cookieString) {
16211622
time_t now_local = time(NULL);
1622-
time_t now_gmt = mktime(gmtime(&now_local));
1623-
1623+
struct tm tm_gmt;
1624+
gmtime_r(&now_local, &tm_gmt);
1625+
time_t now_gmt = mktime(&tm_gmt);
16241626
*cookieString = "";
16251627
bool found = false;
16261628

0 commit comments

Comments
 (0)