]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
--help: strdup the category
authorDaniel Stenberg <daniel@haxx.se>
Fri, 18 Sep 2020 06:09:09 +0000 (08:09 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 18 Sep 2020 12:47:23 +0000 (14:47 +0200)
... since it is converted and the original pointer is freed on Windows
unicode handling.

Follow-up to aa8777f63febc
Fixes #5977
Closes #5978
Reported-by: xwxbug on github
src/tool_getparam.c
src/tool_help.c
src/tool_help.h

index a884f4b3813933bbfb9d90c11f788f227c2eabaf..7977c3dc614a625e4b47b9303ef4c6bfc2877300 100644 (file)
@@ -1777,7 +1777,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
 
     case 'h': /* h for help */
       if(toggle) {
-        global->help_category = nextarg;
+        if(nextarg) {
+          global->help_category = strdup(nextarg);
+          if(!global->help_category)
+            return PARAM_NO_MEM;
+        }
         return PARAM_HELP_REQUESTED;
       }
       /* we now actually support --no-help too! */
index 54a37e6b22598d4209570fd33761835e9223681d..a67e4bc85ab88a315d190bd95d7349c168957c31 100644 (file)
@@ -899,35 +899,31 @@ static void get_categories(void)
 }
 
 
-void tool_help(const char *category)
+void tool_help(char *category)
 {
   puts("Usage: curl [options...] <url>");
   /* If no category was provided */
   if(!category) {
     const char *category_note = "\nThis is not the full help, this "
-    "menu is stripped into categories.\nUse \"--help category\" to get "
-    "an overview of all categories.\nFor all options use the manual"
-    " or \"--help all\".";
+      "menu is stripped into categories.\nUse \"--help category\" to get "
+      "an overview of all categories.\nFor all options use the manual"
+      " or \"--help all\".";
     print_category(CURLHELP_IMPORTANT);
     puts(category_note);
-    return;
   }
   /* Lets print everything if "all" was provided */
-  if(curl_strequal(category, "all")) {
+  else if(curl_strequal(category, "all"))
     /* Print everything except hidden */
     print_category(~(CURLHELP_HIDDEN));
-    return;
-  }
   /* Lets handle the string "category" differently to not print an errormsg */
-  if(curl_strequal(category, "category")) {
+  else if(curl_strequal(category, "category"))
     get_categories();
-    return;
-  }
   /* Otherwise print category and handle the case if the cat was not found */
-  if(get_category_content(category)) {
+  else if(get_category_content(category)) {
     puts("Invalid category provided, here is a list of all categories:\n");
     get_categories();
   }
+  free(category);
 }
 
 static int
index 536ac10f81f1dddcc12e9d44dcfb6ca1c48d03b6..1da23cc54aa6efc66fed060e3326d1f7493cfc7c 100644 (file)
@@ -23,7 +23,7 @@
  ***************************************************************************/
 #include "tool_setup.h"
 
-void tool_help(const char *category);
+void tool_help(char *category);
 void tool_list_engines(void);
 void tool_version_info(void);