From 447bc0d8d9130adc979ea46abd87373aed2cf91f Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Sun, 27 Apr 2025 16:23:30 +0200 Subject: [PATCH] cpuid_tool: replace strcpy() by strncpy() Warning on OpenBSD: warning: strcpy() is almost always misused, please use strlcpy() --- cpuid_tool/cpuid_tool.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cpuid_tool/cpuid_tool.c b/cpuid_tool/cpuid_tool.c index 3c4b35f..437f161 100644 --- a/cpuid_tool/cpuid_tool.c +++ b/cpuid_tool/cpuid_tool.c @@ -54,8 +54,10 @@ #include "libcpuid.h" /* Globals: */ -char raw_data_file[256] = ""; -char out_file[256] = ""; +#define RAW_DATA_FILE_MAX 256 +#define OUT_FILE_MAX 256 +char raw_data_file[RAW_DATA_FILE_MAX] = ""; +char out_file[OUT_FILE_MAX] = ""; typedef enum { NEED_CPUID_PRESENT, NEED_ARCHITECTURE, @@ -237,8 +239,8 @@ static int parse_cmdline(int argc, char** argv) if (argc == 1) { /* Default command line options */ need_output = 1; - strcpy(raw_data_file, "raw.txt"); - strcpy(out_file, "report.txt"); + strncpy(raw_data_file, "raw.txt", RAW_DATA_FILE_MAX); + strncpy(out_file, "report.txt", OUT_FILE_MAX); need_report = 1; verbose_level = 1; return 1; @@ -261,7 +263,7 @@ static int parse_cmdline(int argc, char** argv) xerror("--load: bad file specification!"); } need_input = 1; - strcpy(raw_data_file, arg + 7); + strncpy(raw_data_file, arg + 7, RAW_DATA_FILE_MAX); recog = 1; } if (!strncmp(arg, "--save=", 7)) { @@ -275,14 +277,14 @@ static int parse_cmdline(int argc, char** argv) xerror("--save: bad file specification!"); } need_output = 1; - strcpy(raw_data_file, arg + 7); + strncpy(raw_data_file, arg + 7, RAW_DATA_FILE_MAX); recog = 1; } if (!strncmp(arg, "--outfile=", 10)) { if (strlen(arg) <= 10) { xerror("--output: bad file specification!"); } - strcpy(out_file, arg + 10); + strncpy(out_file, arg + 10, RAW_DATA_FILE_MAX); recog = 1; } if (!strcmp(arg, "--report") || !strcmp(arg, "--all")) {