diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-06-12 22:28:21 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-06-12 22:28:21 +0200 |
commit | 4e4db5b28319c51a8621cec49ea1aaf8ff78ac2a (patch) | |
tree | 94c11e6165a5675516e92b41f181422b73c7148f /src | |
parent | f7aa1e4b8d433252e1d30436277dfbdd3555feeb (diff) | |
download | polecat-4e4db5b28319c51a8621cec49ea1aaf8ff78ac2a.tar.gz polecat-4e4db5b28319c51a8621cec49ea1aaf8ff78ac2a.zip |
make net init explicit, fix lutris URL escape invalid read
Diffstat (limited to 'src')
-rw-r--r-- | src/dxvk.c | 5 | ||||
-rw-r--r-- | src/lutris.c | 19 | ||||
-rw-r--r-- | src/net.c | 13 | ||||
-rw-r--r-- | src/net.h | 4 | ||||
-rw-r--r-- | src/wine.c | 15 |
5 files changed, 42 insertions, 14 deletions
@@ -30,11 +30,11 @@ COMMAND(dxvk, download) { if (argc == 2) { + net_init(); struct json_object* runner = fetchJSON(DXVK_API); if (runner) { - struct json_object* value, *temp, *temp2; uint8_t found = 0; @@ -91,6 +91,7 @@ COMMAND(dxvk, download) json_object_put(runner); } + net_deinit(); } else { @@ -138,6 +139,7 @@ COMMAND(dxvk, remove) COMMAND(dxvk, list) { + net_init(); struct json_object* runner = fetchJSON(DXVK_API); if (runner) @@ -158,6 +160,7 @@ COMMAND(dxvk, list) json_object_put(runner); } + net_deinit(); return EXIT_SUCCESS; } diff --git a/src/lutris.c b/src/lutris.c index 7e94c21..fdf470c 100644 --- a/src/lutris.c +++ b/src/lutris.c @@ -36,6 +36,8 @@ COMMAND(lutris, search) { if (argc > 1 && argv[1][0] != '\0') { + net_init(); + size_t str_size = 0; for (int i = 1; i < argc; ++i) { @@ -49,7 +51,7 @@ COMMAND(lutris, search) // escapeString can return is strlen*3 str_size *= 3; - char* str = malloc(str_size); + char* str = malloc(str_size+1); if (!str) return 1; str[0] = '\0'; @@ -58,7 +60,7 @@ COMMAND(lutris, search) if (i != 1) strncat(str, " ", str_size); strncat(str, argv[i], str_size); } - str[str_size-1] = '\0'; + str[str_size] = '\0'; lutris_escapeString(str, str_size); char* url = malloc(strlen(LUTRIS_GAME_SEARCH_API) + strlen(str)); @@ -89,6 +91,7 @@ COMMAND(lutris, search) json_object_put(queryresult); } + net_deinit(); } else { @@ -102,6 +105,8 @@ COMMAND(lutris, list) { if (argc == 2) { + net_init(); + // argv being modifyable is not always a given so lets // lets make a mutable copy char* str = strdup(argv[1]); @@ -145,6 +150,7 @@ COMMAND(lutris, list) json_object_put(queryresult); } + net_deinit(); } else { @@ -158,6 +164,7 @@ COMMAND(lutris, install) { if (argc == 2) { + net_init(); struct script_t installer = lutris_getInstaller(argv[1]); if (installer.error == NONE) @@ -310,6 +317,7 @@ COMMAND(lutris, install) } lutris_freeInstaller(&installer); + net_deinit(); } return EXIT_SUCCESS; } @@ -318,6 +326,7 @@ COMMAND(lutris, info) { if (argc == 2) { + net_init(); struct script_t installer = lutris_getInstaller(argv[1]); if (installer.error > NO_SLUG || installer.error == NONE) @@ -389,6 +398,7 @@ COMMAND(lutris, info) } lutris_freeInstaller(&installer); + net_deinit(); } else { @@ -401,9 +411,12 @@ COMMAND_HELP(lutris, " lutris") void lutris_escapeString(char* str, size_t size) { + if (!str || !*str) + return; + char* tail = str + size; - while (str != tail) + while (*str && str < tail) { switch (*str) { @@ -9,6 +9,16 @@ #include "net.h" #include "common.h" +void net_init() +{ + curl_global_init(CURL_GLOBAL_ALL); +} + +void net_deinit() +{ + curl_global_cleanup(); +} + static inline size_t memoryCallback(const void* contents, size_t size, size_t nmemb, void* userp) { size_t realsize = size * nmemb; @@ -65,8 +75,6 @@ struct MemoryStruct* downloadToRam(const char* URL, int progress) chunk->memory[0] = 0; chunk->size = 0; - curl_global_init(CURL_GLOBAL_ALL); - curl_handle = curl_easy_init(); curl_easy_setopt(curl_handle, CURLOPT_URL, URL); @@ -99,7 +107,6 @@ struct MemoryStruct* downloadToRam(const char* URL, int progress) } curl_easy_cleanup(curl_handle); - curl_global_cleanup(); } else { @@ -4,9 +4,9 @@ #include <curl/curl.h> #include <json.h> -#define TIMEOPT CURLINFO_TOTAL_TIME_T +void net_init(); +void net_deinit(); -size_t WriteMemoryCallback(void*, size_t, size_t, void*); struct MemoryStruct* downloadToRam(const char* URL, int); void downloadToFile(const char*, const char*, int); struct json_object* fetchJSON(const char*); @@ -35,6 +35,7 @@ COMMAND(winecmd, download) { if (argc >= 2) { + net_init(); struct json_object* runner = fetchJSON(WINE_API); if (runner) @@ -98,11 +99,13 @@ COMMAND(winecmd, download) json_object_put(runner); } + net_deinit(); } else { fprintf(stderr, USAGE_STR " wine download [versions]\n\nversions are obtained via '" NAME " wine list'\n"); } + return EXIT_SUCCESS; } @@ -160,6 +163,7 @@ COMMAND(winecmd, remove) COMMAND(winecmd, list) { + net_init(); struct json_object* runner = fetchJSON(WINE_API); if (runner) @@ -182,6 +186,7 @@ COMMAND(winecmd, list) json_object_put(runner); } + net_deinit(); return EXIT_SUCCESS; } @@ -346,7 +351,7 @@ COMMAND(winecmd, env) printf("To add a wine installation to your PATH\n" "you have to eval the output.\n\n"); if (!fish_env) - printf("$ eval 'polecat wine env %s'\n", winever); + printf("$ eval `polecat wine env %s`\n", winever); else printf("$ eval (polecat wine fish-env %s)\n", winever); } @@ -385,8 +390,8 @@ enum wine_type_t check_wine_ver(char* winepath, size_t size) winepathcopy = malloc(size); if (winepathcopy) { - strncpy(winepathcopy, winepath, size); - strncat(winepathcopy, WINEBIN, size - strlen(winepathcopy)); + strncpy(winepathcopy, winepath, size - 1); + strncat(winepathcopy, WINEBIN, size - strlen(winepathcopy) - 1); if (isFile(winepathcopy)) { @@ -394,8 +399,8 @@ enum wine_type_t check_wine_ver(char* winepath, size_t size) return WINE_NORMAL; } - strncpy(winepathcopy, winepath, size); - strncat(winepathcopy, PROTONBIN, size - strlen(winepathcopy)); + strncpy(winepathcopy, winepath, size - 1); + strncat(winepathcopy, PROTONBIN, size - strlen(winepathcopy) - 1); if (isFile(winepathcopy)) { |