From 29e2a82e8a8fee9be655707da44106970b88b8bb Mon Sep 17 00:00:00 2001 From: g3gg0 Date: Thu, 27 Jul 2023 00:54:44 +0200 Subject: [PATCH] fix warnings and potential edge cases --- src/cyclone/cyclone_tcp/http/http_server_misc.c | 2 +- src/handler_rtnl.c | 2 +- src/tls_adapter.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cyclone/cyclone_tcp/http/http_server_misc.c b/src/cyclone/cyclone_tcp/http/http_server_misc.c index a927862c..4b4f0b13 100644 --- a/src/cyclone/cyclone_tcp/http/http_server_misc.c +++ b/src/cyclone/cyclone_tcp/http/http_server_misc.c @@ -605,7 +605,7 @@ void httpParseContentTypeField(HttpConnection *connection, if (n < HTTP_SERVER_BOUNDARY_MAX_LEN) { // Copy the boundary string - osStrncpy(connection->request.boundary, token, n); + osStrcpy(connection->request.boundary, token); // Properly terminate the string connection->request.boundary[n] = '\0'; diff --git a/src/handler_rtnl.c b/src/handler_rtnl.c index 33e3b143..8b0b3417 100644 --- a/src/handler_rtnl.c +++ b/src/handler_rtnl.c @@ -68,7 +68,7 @@ static void escapeString(const char_t *input, size_t size, char_t *output) if (input[i] == replacements[k][0]) { size_t len = osStrlen(replacements[k]); - osStrncpy(&output[j], replacements[k], len); + osStrcpy(&output[j], replacements[k]); j += len; replaced = true; break; diff --git a/src/tls_adapter.c b/src/tls_adapter.c index f103acad..a023979e 100644 --- a/src/tls_adapter.c +++ b/src/tls_adapter.c @@ -70,8 +70,14 @@ error_t der_get_length(FsFile *fp, size_t *outLength) uint32_t length = 0; for (uint8_t i = 0; i < num_bytes; i++) { - fread(&len, 1, 1, fp); - length = (length << 8) | len; + error_t err = fsReadFile(fp, &derLen, 1, &len); + if (err != NO_ERROR || len != 1) + { + *outLength = 0; + return err; + } + + length = (length << 8) | derLen; } *outLength = length; } @@ -253,7 +259,7 @@ error_t read_certificate(const char_t *filename, char_t **buffer, size_t *length // Close file if (fp != NULL) - fclose(fp); + fsCloseFile(fp); // Any error to report? if (error)