From 3795a64b775107bac77e03bbd2601402de57e043 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 25 Jul 2020 23:37:06 -0700 Subject: [PATCH] Test: I added strlcpy for a reason --- src/platform/test/cinema-main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/platform/test/cinema-main.c b/src/platform/test/cinema-main.c index 2a9206f65..d2f105305 100644 --- a/src/platform/test/cinema-main.c +++ b/src/platform/test/cinema-main.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -127,7 +128,7 @@ static bool parseCInemaArgs(int argc, char* const* argv) { } break; case 'b': - strncpy(base, optarg, sizeof(base)); + strlcpy(base, optarg, sizeof(base)); // TODO: Verify path exists break; case 'd': @@ -140,7 +141,7 @@ static bool parseCInemaArgs(int argc, char* const* argv) { dryRun = true; break; case 'o': - strncpy(outdir, optarg, sizeof(outdir)); + strlcpy(outdir, optarg, sizeof(outdir)); // TODO: Make directory break; case 'q': @@ -244,7 +245,7 @@ static void reduceTestList(struct CInemaTestList* tests) { } static void testToPath(const char* testName, char* path) { - strncpy(path, base, PATH_MAX); + strlcpy(path, base, PATH_MAX); bool dotSeen = true; size_t i; @@ -253,7 +254,7 @@ static void testToPath(const char* testName, char* path) { dotSeen = true; } else { if (dotSeen) { - strncpy(&path[i], PATH_SEP, PATH_MAX - i); + strlcpy(&path[i], PATH_SEP, PATH_MAX - i); i += strlen(PATH_SEP); dotSeen = false; if (!i) { @@ -268,7 +269,7 @@ static void testToPath(const char* testName, char* path) { static void _loadConfigTree(struct Table* configTree, const char* testName) { char key[MAX_TEST]; - strncpy(key, testName, sizeof(key) - 1); + strlcpy(key, testName, sizeof(key)); struct mCoreConfig* config; while (!(config = HashTableLookup(configTree, key))) { @@ -301,7 +302,7 @@ static const char* _lookupValue(struct Table* configTree, const char* testName, _loadConfigTree(configTree, testName); char testKey[MAX_TEST]; - strncpy(testKey, testName, sizeof(testKey) - 1); + strlcpy(testKey, testName, sizeof(testKey)); struct mCoreConfig* config; while (true) { @@ -378,10 +379,10 @@ bool CInemaTestInit(struct CInemaTest* test, const char* directory, const char* return false; } memset(test, 0, sizeof(*test)); - strncpy(test->directory, directory, sizeof(test->directory) - 1); - strncpy(test->filename, filename, sizeof(test->filename) - 1); + strlcpy(test->directory, directory, sizeof(test->directory)); + strlcpy(test->filename, filename, sizeof(test->filename)); directory += strlen(base) + 1; - strncpy(test->name, directory, sizeof(test->name) - 1); + strlcpy(test->name, directory, sizeof(test->name)); char* str = strstr(test->name, PATH_SEP); while (str) { str[0] = '.'; @@ -446,7 +447,7 @@ static bool _loadBaseline(struct VDir* dir, struct CInemaImage* image, size_t fr static struct VDir* _makeOutDir(const char* testName) { char path[PATH_MAX] = {0}; - strncpy(path, outdir, sizeof(path) - 1); + strlcpy(path, outdir, sizeof(path)); char* pathEnd = path + strlen(path); const char* pos; while (true) { @@ -768,7 +769,7 @@ int main(int argc, char** argv) { #ifndef _WIN32 char* rbase = realpath(base, NULL); if (rbase) { - strncpy(base, rbase, PATH_MAX); + strlcpy(base, rbase, sizeof(base)); free(rbase); } #endif