texlive[53455] Build/source/texk/kpathsea: ensure nonempty argument

commits+karl at tug.org commits+karl at tug.org
Sun Jan 19 18:25:18 CET 2020


Revision: 53455
          http://tug.org/svn/texlive?view=revision&revision=53455
Author:   karl
Date:     2020-01-19 18:25:18 +0100 (Sun, 19 Jan 2020)
Log Message:
-----------
ensure nonempty argument string to --var-value, etc.

Modified Paths:
--------------
    trunk/Build/source/texk/kpathsea/ChangeLog
    trunk/Build/source/texk/kpathsea/kpsewhich.c

Modified: trunk/Build/source/texk/kpathsea/ChangeLog
===================================================================
--- trunk/Build/source/texk/kpathsea/ChangeLog	2020-01-19 17:04:02 UTC (rev 53454)
+++ trunk/Build/source/texk/kpathsea/ChangeLog	2020-01-19 17:25:18 UTC (rev 53455)
@@ -1,5 +1,10 @@
 2020-01-19  Karl Berry  <karl at freefriends.org>
 
+	* kpsewhich.c (ENSURE_NONEMPTY_STRING): new macro.
+	(read_command_line): ensure nonempty arguments to --format,
+	--safe-{in,out}-name, --var-brace-value, --var-value.
+	Empty args to the other options seem possible.
+
 	* line.c (read_line): silently drop nul (zero) bytes.
 	* tests/cnfnull.test: test for nul bytes in texmf.cnf.
 	* Makefile.am (TESTS),

Modified: trunk/Build/source/texk/kpathsea/kpsewhich.c
===================================================================
--- trunk/Build/source/texk/kpathsea/kpsewhich.c	2020-01-19 17:04:02 UTC (rev 53454)
+++ trunk/Build/source/texk/kpathsea/kpsewhich.c	2020-01-19 17:25:18 UTC (rev 53455)
@@ -589,6 +589,14 @@
    option table in a variable `long_options'.  */
 #define ARGUMENT_IS(a) STREQ (long_options[option_index].name, a)
 
+/* If S is NULL or the empty string, abort.  */
+#define ENSURE_NONEMPTY_STRING(s) do {                                \
+  if (!(s) || ! *(s)) {                                               \
+    fprintf (stderr, "kpsewhich: empty argument for %s\n",            \
+             long_options[option_index].name);                        \
+    fputs ("Try `kpsewhich --help' for more information.\n", stderr); \
+    exit (EXIT_FAILURE); } } while (0)
+
 /* SunOS cc can't initialize automatic structs.  */
 static struct option long_options[]
   = { { "D",                    1, 0, 0 },
@@ -634,7 +642,7 @@
       break;
 
     if (g == '?')
-      exit (1);  /* Unknown option.  */
+      exit (EXIT_FAILURE);  /* Unknown option.  */
 
     assert (g == 0); /* We have no short option names.  */
 
@@ -674,6 +682,7 @@
       var_to_expand = optarg;
 
     } else if (ARGUMENT_IS ("format")) {
+      ENSURE_NONEMPTY_STRING (optarg);
       user_format_string = optarg;
 
     } else if (ARGUMENT_IS ("help")) {
@@ -703,9 +712,11 @@
       progname = optarg;
 
     } else if (ARGUMENT_IS ("safe-in-name")) {
+      ENSURE_NONEMPTY_STRING (optarg);
       safe_in_name = optarg;
 
     } else if (ARGUMENT_IS ("safe-out-name")) {
+      ENSURE_NONEMPTY_STRING (optarg);
       safe_out_name = optarg;
 
     } else if (ARGUMENT_IS ("show-path")) {
@@ -716,14 +727,16 @@
       str_list_add (&subdir_paths, optarg);
 
     } else if (ARGUMENT_IS ("var-brace-value")) {
+      ENSURE_NONEMPTY_STRING (optarg);
       var_to_brace_value = optarg;
 
     } else if (ARGUMENT_IS ("var-value")) {
+      ENSURE_NONEMPTY_STRING (optarg);
       var_to_value = optarg;
 
     } else if (ARGUMENT_IS ("version")) {
       puts (kpathsea_version_string);
-      puts ("Copyright 2019 Karl Berry & Olaf Weber.\n\
+      puts ("Copyright 2020 Karl Berry & Olaf Weber.\n\
 License LGPLv2.1+: GNU Lesser GPL version 2.1 or later <https://gnu.org/licenses/lgpl.html>\n\
 This is free software: you are free to change and redistribute it.\n\
 There is NO WARRANTY, to the extent permitted by law.\n");
@@ -734,10 +747,11 @@
   }
 
   if (user_path && user_format_string) {
-    fprintf (stderr, "-path (%s) and -format (%s) are mutually exclusive.\n",
+    fprintf (stderr,
+            "kpsewhich: -path (%s) and -format (%s) are mutually exclusive.\n",
              user_path, user_format_string);
     fputs ("Try `kpsewhich --help' for more information.\n", stderr);
-    exit (1);
+    exit (EXIT_FAILURE);
   }
 
   if (optind == argc
@@ -746,7 +760,7 @@
       && !safe_in_name && !safe_out_name) {
     fputs ("Missing argument. Try `kpsewhich --help' for more information.\n",
            stderr);
-    exit (1);
+    exit (EXIT_FAILURE);
   }
 }
 



More information about the tex-live-commits mailing list