changeset 40082:6b4f59f81014

argp: Don't pass an invalid argument to dgettext(). Reported by He X <xw897002528@gmail.com>. * lib/argp.h (struct argp): Clarify that the args_doc field may be NULL. * lib/argp-help.c (argp_args_usage): Don't pass a NULL args_doc to dgettext().
author Bruno Haible <bruno@clisp.org>
date Sat, 05 Jan 2019 17:00:53 +0100
parents 9cfd9ce6fa82
children 05c92cba4eaa
files ChangeLog lib/argp-help.c lib/argp.h
diffstat 3 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Dec 22 18:00:10 2018 -0800
+++ b/ChangeLog	Sat Jan 05 17:00:53 2019 +0100
@@ -1,3 +1,11 @@
+2019-01-05  Bruno Haible  <bruno@clisp.org>
+
+	argp: Don't pass an invalid argument to dgettext().
+	Reported by He X <xw897002528@gmail.com>.
+	* lib/argp.h (struct argp): Clarify that the args_doc field may be NULL.
+	* lib/argp-help.c (argp_args_usage): Don't pass a NULL args_doc to
+	dgettext().
+
 2018-12-22  Paul Eggert  <eggert@cs.ucla.edu>
 
 	stdioext: port to newer 32-bit Android
--- a/lib/argp-help.c	Sat Dec 22 18:00:10 2018 -0800
+++ b/lib/argp-help.c	Sat Jan 05 17:00:53 2019 +0100
@@ -1412,8 +1412,10 @@
   char *our_level = *levels;
   int multiple = 0;
   const struct argp_child *child = argp->children;
-  const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
+  const char *tdoc =
+    argp->args_doc ? dgettext (argp->argp_domain, argp->args_doc) : NULL;
   const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
+  const char *nl = NULL;
 
   if (fdoc)
     {
--- a/lib/argp.h	Sat Dec 22 18:00:10 2018 -0800
+++ b/lib/argp.h	Sat Jan 05 17:00:53 2019 +0100
@@ -69,6 +69,9 @@
 extern "C" {
 #endif
 
+/* Glibc documentation:
+   https://www.gnu.org/software/libc/manual/html_node/Argp.html */
+
 /* A description of a particular option.  A pointer to an array of
    these is passed in the OPTIONS field of an argp structure.  Each option
    entry can correspond to one long option and/or one short option; more
@@ -236,9 +239,9 @@
      ARGP_KEY_ definitions below.  */
   argp_parser_t parser;
 
-  /* A string describing what other arguments are wanted by this program.  It
-     is only used by argp_usage to print the "Usage:" message.  If it
-     contains newlines, the strings separated by them are considered
+  /* If non-NULL, a string describing what other arguments are wanted by this
+     program.  It is only used by argp_usage to print the "Usage:" message.
+     If it contains newlines, the strings separated by them are considered
      alternative usage patterns, and printed on separate lines (lines after
      the first are prefix by "  or: " instead of "Usage:").  */
   const char *args_doc;