diff options
| author | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2011-07-04 09:19:37 +0000 |
|---|---|---|
| committer | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2011-07-04 09:19:37 +0000 |
| commit | bb6b4df34f8e1591f46c4e2936c380efaf32d71c (patch) | |
| tree | 457b73f4ad504c56bdca7e66cb230a950424b759 /Projects | |
| parent | 7b8b2b442882c115da1ce32e98f635039370d4e3 (diff) | |
Switch the HTTP Webserver project to use the safer strlcpy() instead of strncpy() to save on manual null-termination.
git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@1841 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'Projects')
| -rw-r--r-- | Projects/Webserver/Lib/HTTPServerApp.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/Projects/Webserver/Lib/HTTPServerApp.c b/Projects/Webserver/Lib/HTTPServerApp.c index d7585fe9..37377d0a 100644 --- a/Projects/Webserver/Lib/HTTPServerApp.c +++ b/Projects/Webserver/Lib/HTTPServerApp.c @@ -181,10 +181,7 @@ static void HTTPServerApp_OpenRequestedFile(void) } /* Copy over the requested filename */ - strncpy(AppState->HTTPServer.FileName, &RequestedFileName[1], sizeof(AppState->HTTPServer.FileName)); - - /* Ensure filename is null-terminated */ - AppState->HTTPServer.FileName[sizeof(AppState->HTTPServer.FileName) - 1] = 0x00; + strlcpy(AppState->HTTPServer.FileName, &RequestedFileName[1], sizeof(AppState->HTTPServer.FileName)); /* 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); @@ -192,11 +189,8 @@ static void HTTPServerApp_OpenRequestedFile(void) /* If the URI is a directory, append the default filename */ 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)); - - /* 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 */ |
