From e83fafc1895d72f9c1e4bd701c90b325629ea305 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 4 Sep 2020 19:14:58 +0200 Subject: correct strn sizes, replace str calls with strn variant, check wine path --- src/wine.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/wine.c b/src/wine.c index 0f9796e..ed428ef 100644 --- a/src/wine.c +++ b/src/wine.c @@ -69,9 +69,9 @@ int wine_download(int argc, char** argv) getDataDir(datadir, sizeof(datadir)); makeDir(datadir); - strncpy(downloadpath, datadir, sizeof(downloadpath)); - strncat(downloadpath, "/", sizeof(downloadpath) - strlen(downloadpath)); - strncat(downloadpath, name, sizeof(downloadpath) - strlen(downloadpath)); + strncpy(downloadpath, datadir, sizeof(downloadpath) - 1); + strncat(downloadpath, "/", sizeof(downloadpath) - strlen(downloadpath) - 1); + strncat(downloadpath, name, sizeof(downloadpath) - strlen(downloadpath) - 1); printf("Downloading %s\n", name); @@ -134,20 +134,30 @@ int wine_run(int argc, char** argv) getDataDir(winepath, sizeof(winepath)); char* winever = argv[1]; - strcat(winepath, "/"); - strcat(winepath, winever); - strcat(winepath, "/bin/wine"); + strncat(winepath, "/", sizeof(winepath) - strlen(winepath) - 1); + strncat(winepath, winever, sizeof(winepath) - strlen(winepath) - 1); + strncat(winepath, "/bin/wine", sizeof(winepath) - strlen(winepath) - 1); - for (int i = 2; i < argc; ++i) + if (isFile(winepath)) { - strcat(winepath, " "); - strcat(winepath, argv[i]); + for (int i = 2; i < argc; ++i) + { + strncat(winepath, " ", sizeof(winepath) - strlen(winepath) - 1); + strncat(winepath, argv[i], sizeof(winepath) - strlen(winepath) - 1); + } + return system(winepath); + } + else + { + printf("`%s' is not an installed wine version\n", winever); } - return system(winepath); + } + else + { + printf("Specify a what wine version to run.\nUse `" NAME " wine installed' to list available versions\n"); } - printf("Specify a what wine version to run.\nUse `" NAME " wine list-installed' to list available versions\n"); return 0; } @@ -187,4 +197,4 @@ int wine_help(int argc, char** argv) print_help(wine_commands, ARRAY_LEN(wine_commands)); return 0; -} \ No newline at end of file +} -- cgit v1.2.3