forked from mfulz_github/qmk_firmware
Switch the HTTP Webserver project to use the safer strlcpy() instead of strncpy() to save on manual null-termination.
This commit is contained in:
parent
61861c548e
commit
a09e1cb53b
|
@ -181,10 +181,7 @@ static void HTTPServerApp_OpenRequestedFile(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy over the requested filename */
|
/* Copy over the requested filename */
|
||||||
strncpy(AppState->HTTPServer.FileName, &RequestedFileName[1], sizeof(AppState->HTTPServer.FileName));
|
strlcpy(AppState->HTTPServer.FileName, &RequestedFileName[1], sizeof(AppState->HTTPServer.FileName));
|
||||||
|
|
||||||
/* Ensure filename is null-terminated */
|
|
||||||
AppState->HTTPServer.FileName[sizeof(AppState->HTTPServer.FileName) - 1] = 0x00;
|
|
||||||
|
|
||||||
/* Determine the length of the URI so that it can be checked to see if it is a directory */
|
/* Determine the length of the URI so that it can be checked to see if it is a directory */
|
||||||
uint8_t FileNameLen = strlen(AppState->HTTPServer.FileName);
|
uint8_t FileNameLen = strlen(AppState->HTTPServer.FileName);
|
||||||
|
@ -192,11 +189,8 @@ static void HTTPServerApp_OpenRequestedFile(void)
|
||||||
/* If the URI is a directory, append the default filename */
|
/* If the URI is a directory, append the default filename */
|
||||||
if ((AppState->HTTPServer.FileName[FileNameLen - 1] == '/') || !(FileNameLen))
|
if ((AppState->HTTPServer.FileName[FileNameLen - 1] == '/') || !(FileNameLen))
|
||||||
{
|
{
|
||||||
strncpy_P(&AppState->HTTPServer.FileName[FileNameLen], DefaultDirFileName,
|
strlcpy_P(&AppState->HTTPServer.FileName[FileNameLen], DefaultDirFileName,
|
||||||
(sizeof(AppState->HTTPServer.FileName) - FileNameLen));
|
(sizeof(AppState->HTTPServer.FileName) - FileNameLen));
|
||||||
|
|
||||||
/* Ensure altered filename is still null-terminated */
|
|
||||||
AppState->HTTPServer.FileName[sizeof(AppState->HTTPServer.FileName) - 1] = 0x00;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to open the file from the Dataflash disk */
|
/* Try to open the file from the Dataflash disk */
|
||||||
|
|
Loading…
Reference in New Issue