From 4d87fb23979a957b806c0b1098a703c508d0f0c7 Mon Sep 17 00:00:00 2001 From: Sami Ahovainio Date: Thu, 10 Sep 2020 12:57:25 +0300 Subject: [PATCH] fixed potential out of bounds iteration --- src/cfg.c | 9 +-------- src/cli.c | 5 +++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index 60bfcd3e..02218fa8 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -21,7 +21,6 @@ #include "cfg.h" #include "gop.h" -#include #include #include #include @@ -1366,12 +1365,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) } else if OPT("input-file-format") { int8_t file_format = 0; - char value_lower_case[255]; - for (int i = 0; i < 255; i++) { - value_lower_case[i] = tolower(value[i]); - } - fprintf(stderr, "value: %s ", value_lower_case); - if (!parse_enum(value_lower_case, file_format_names, &file_format)) { + if (!parse_enum(value, file_format_names, &file_format)) { fprintf(stderr, "Invalid input file format %s. Valid values include %s, %s, and %s\n", value, file_format_names[0], file_format_names[1], @@ -1379,7 +1373,6 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) return 0; } cfg->file_format = file_format; - fprintf(stderr, "%i\n", cfg->file_format); } else { return 0; diff --git a/src/cli.c b/src/cli.c index d6ea1183..809bad03 100644 --- a/src/cli.c +++ b/src/cli.c @@ -198,14 +198,15 @@ static int detect_file_format(const char *file_name) { // If delim is not found, return 0 char* sub_str = (char*)strrchr(file_name, '.'); if (!sub_str) return 0; + if (strlen(sub_str) != 4) return 0; char ending_lower_case[4]; for(int i = 0; i < 4; i++){ ending_lower_case[i] = tolower(sub_str[i]); } // KVZ_FILE_FORMAT - if (strcmp(ending_lower_case, ".y4m") == 0) return 1; - else if (strcmp(ending_lower_case, ".yuv") == 0) return 2; + if (strncmp(ending_lower_case, ".y4m", 4) == 0) return 1; + else if (strncmp(ending_lower_case, ".yuv", 4) == 0) return 2; return 0; }