From bc26bc589668687168f30f9be296a3a4d0cc68af Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Fri, 29 Sep 2023 12:06:05 +0200 Subject: [PATCH 1/5] xmlwf: Break up conditional before upcoming extension --- expat/xmlwf/xmlwf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index c84fcd77..48724b48 100644 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -984,9 +984,11 @@ tmain(int argc, XML_Char **argv) { if (j == 0) { if (argv[i][0] != T('-')) break; - if (argv[i][1] == T('-') && argv[i][2] == T('\0')) { - i++; - break; + if (argv[i][1] == T('-')) { + if (argv[i][2] == T('\0')) { + i++; + break; + } } j++; } From 900d2a7cd20adab59f506d2f2289faa3fa48f8f5 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Fri, 29 Sep 2023 12:26:52 +0200 Subject: [PATCH 2/5] xmlwf: Better document that usage(..) calls exit(..) --- expat/xmlwf/xmlwf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index 48724b48..bf087b4f 100644 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -871,6 +871,9 @@ showVersion(XML_Char *prog) { } } +#if defined(__GNUC__) +__attribute__((noreturn)) +#endif static void usage(const XML_Char *prog, int rc) { ftprintf( @@ -941,8 +944,10 @@ int wmain(int argc, XML_Char **argv); #define XMLWF_SHIFT_ARG_INTO(constCharStarTarget, argc, argv, i, j) \ { \ if (argv[i][j + 1] == T('\0')) { \ - if (++i == argc) \ + if (++i == argc) { \ usage(argv[0], XMLWF_EXIT_USAGE_ERROR); \ + /* usage called exit(..), never gets here */ \ + } \ constCharStarTarget = argv[i]; \ } else { \ constCharStarTarget = argv[i] + j + 1; \ @@ -1041,7 +1046,7 @@ tmain(int argc, XML_Char **argv) { break; case T('h'): usage(argv[0], XMLWF_EXIT_SUCCESS); - return 0; + // usage called exit(..), never gets here case T('v'): showVersion(argv[0]); return 0; @@ -1121,6 +1126,7 @@ tmain(int argc, XML_Char **argv) { /* fall through */ default: usage(argv[0], XMLWF_EXIT_USAGE_ERROR); + // usage called exit(..), never gets here } } if (i == argc) { From 0b3ef852bcd2066b7e452639136818cc4b46ab32 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Fri, 29 Sep 2023 12:36:31 +0200 Subject: [PATCH 3/5] xmlwf: Support --help and --version --- expat/xmlwf/xmlwf.c | 14 ++++++++++---- expat/xmlwf/xmlwf_helpgen.py | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index bf087b4f..901c9e33 100644 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -886,8 +886,8 @@ usage(const XML_Char *prog, int rc) { /* clang-format off */ T("usage:\n") T(" %s [OPTIONS] [FILE ...]\n") - T(" %s -h\n") - T(" %s -v\n") + T(" %s -h|--help\n") + T(" %s -v|--version\n") T("\n") T("xmlwf - Determines if an XML document is well-formed\n") T("\n") @@ -919,8 +919,8 @@ usage(const XML_Char *prog, int rc) { T(" -b BYTES set number of output [b]ytes needed to activate (default: 8 MiB)\n") T("\n") T("info arguments:\n") - T(" -h show this [h]elp message and exit\n") - T(" -v show program's [v]ersion number and exit\n") + T(" -h, --help show this [h]elp message and exit\n") + T(" -v, --version show program's [v]ersion number and exit\n") T("\n") T("exit status:\n") T(" 0 the input files are well-formed and the output (if requested) was written successfully\n") @@ -993,6 +993,12 @@ tmain(int argc, XML_Char **argv) { if (argv[i][2] == T('\0')) { i++; break; + } else if (tcscmp(argv[i] + 2, T("help")) == 0) { + usage(argv[0], XMLWF_EXIT_SUCCESS); + // usage called exit(..), never gets here + } else if (tcscmp(argv[i] + 2, T("version")) == 0) { + showVersion(argv[0]); + return XMLWF_EXIT_SUCCESS; } } j++; diff --git a/expat/xmlwf/xmlwf_helpgen.py b/expat/xmlwf/xmlwf_helpgen.py index c9ac9a1e..3f6b4f85 100755 --- a/expat/xmlwf/xmlwf_helpgen.py +++ b/expat/xmlwf/xmlwf_helpgen.py @@ -45,8 +45,8 @@ Please report bugs at https://github.com/libexpat/libexpat/issues -- thank you! usage = """ %(prog)s [OPTIONS] [FILE ...] - %(prog)s -h - %(prog)s -v + %(prog)s -h|--help + %(prog)s -v|--version """ parser = argparse.ArgumentParser(prog='xmlwf', add_help=False, @@ -86,8 +86,8 @@ parser.add_argument('files', metavar='FILE', nargs='*', help='file to process (d info = parser.add_argument_group('info arguments') info = info.add_mutually_exclusive_group() -info.add_argument('-h', action='store_true', help='show this [h]elp message and exit') -info.add_argument('-v', action='store_true', help='show program\'s [v]ersion number and exit') +info.add_argument('-h', '--help', action='store_true', help='show this [h]elp message and exit') +info.add_argument('-v', '--version', action='store_true', help='show program\'s [v]ersion number and exit') if __name__ == '__main__': From 4c6731ad11d8eccc3cf9d4bbb1752956b8e325e7 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Fri, 29 Sep 2023 12:37:23 +0200 Subject: [PATCH 4/5] xmlwf: Use XMLWF_EXIT_SUCCESS where missing --- expat/xmlwf/xmlwf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index 901c9e33..a3e9eb98 100644 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -1055,7 +1055,7 @@ tmain(int argc, XML_Char **argv) { // usage called exit(..), never gets here case T('v'): showVersion(argv[0]); - return 0; + return XMLWF_EXIT_SUCCESS; case T('g'): { const XML_Char *valueText = NULL; XMLWF_SHIFT_ARG_INTO(valueText, argc, argv, i, j); From 92cdc783f146b41a46eb36f47ff2b958f5bcc788 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Fri, 29 Sep 2023 12:42:22 +0200 Subject: [PATCH 5/5] xmlwf: Get help output alignment back in order --- expat/xmlwf/xmlwf.c | 44 ++++++++++++++++++------------------ expat/xmlwf/xmlwf_helpgen.py | 10 ++++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index a3e9eb98..1234b6d3 100644 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -892,42 +892,42 @@ usage(const XML_Char *prog, int rc) { T("xmlwf - Determines if an XML document is well-formed\n") T("\n") T("positional arguments:\n") - T(" FILE file to process (default: STDIN)\n") + T(" FILE file to process (default: STDIN)\n") T("\n") T("input control arguments:\n") - T(" -s print an error if the document is not [s]tandalone\n") - T(" -n enable [n]amespace processing\n") - T(" -p enable processing of external DTDs and [p]arameter entities\n") - T(" -x enable processing of e[x]ternal entities\n") - T(" -e ENCODING override any in-document [e]ncoding declaration\n") - T(" -w enable support for [W]indows code pages\n") - T(" -r disable memory-mapping and use [r]ead calls instead\n") - T(" -g BYTES buffer size to request per call pair to XML_[G]etBuffer and read (default: 8 KiB)\n") - T(" -k when processing multiple files, [k]eep processing after first file with error\n") + T(" -s print an error if the document is not [s]tandalone\n") + T(" -n enable [n]amespace processing\n") + T(" -p enable processing of external DTDs and [p]arameter entities\n") + T(" -x enable processing of e[x]ternal entities\n") + T(" -e ENCODING override any in-document [e]ncoding declaration\n") + T(" -w enable support for [W]indows code pages\n") + T(" -r disable memory-mapping and use [r]ead calls instead\n") + T(" -g BYTES buffer size to request per call pair to XML_[G]etBuffer and read (default: 8 KiB)\n") + T(" -k when processing multiple files, [k]eep processing after first file with error\n") T("\n") T("output control arguments:\n") - T(" -d DIRECTORY output [d]estination directory\n") - T(" -c write a [c]opy of input XML, not canonical XML\n") - T(" -m write [m]eta XML, not canonical XML\n") - T(" -t write no XML output for [t]iming of plain parsing\n") - T(" -N enable adding doctype and [n]otation declarations\n") + T(" -d DIRECTORY output [d]estination directory\n") + T(" -c write a [c]opy of input XML, not canonical XML\n") + T(" -m write [m]eta XML, not canonical XML\n") + T(" -t write no XML output for [t]iming of plain parsing\n") + T(" -N enable adding doctype and [n]otation declarations\n") T("\n") T("billion laughs attack protection:\n") T(" NOTE: If you ever need to increase these values for non-attack payload, please file a bug report.\n") T("\n") - T(" -a FACTOR set maximum tolerated [a]mplification factor (default: 100.0)\n") - T(" -b BYTES set number of output [b]ytes needed to activate (default: 8 MiB)\n") + T(" -a FACTOR set maximum tolerated [a]mplification factor (default: 100.0)\n") + T(" -b BYTES set number of output [b]ytes needed to activate (default: 8 MiB)\n") T("\n") T("info arguments:\n") T(" -h, --help show this [h]elp message and exit\n") T(" -v, --version show program's [v]ersion number and exit\n") T("\n") T("exit status:\n") - T(" 0 the input files are well-formed and the output (if requested) was written successfully\n") - T(" 1 could not allocate data structures, signals a serious problem with execution environment\n") - T(" 2 one or more input files were not well-formed\n") - T(" 3 could not create an output file\n") - T(" 4 command-line argument error\n") + T(" 0 the input files are well-formed and the output (if requested) was written successfully\n") + T(" 1 could not allocate data structures, signals a serious problem with execution environment\n") + T(" 2 one or more input files were not well-formed\n") + T(" 3 could not create an output file\n") + T(" 4 command-line argument error\n") T("\n") T("xmlwf of libexpat is software libre, licensed under the MIT license.\n") T("Please report bugs at https://github.com/libexpat/libexpat/issues -- thank you!\n") diff --git a/expat/xmlwf/xmlwf_helpgen.py b/expat/xmlwf/xmlwf_helpgen.py index 3f6b4f85..7f89a4e9 100755 --- a/expat/xmlwf/xmlwf_helpgen.py +++ b/expat/xmlwf/xmlwf_helpgen.py @@ -33,11 +33,11 @@ import argparse epilog = """ exit status: - 0 the input files are well-formed and the output (if requested) was written successfully - 1 could not allocate data structures, signals a serious problem with execution environment - 2 one or more input files were not well-formed - 3 could not create an output file - 4 command-line argument error + 0 the input files are well-formed and the output (if requested) was written successfully + 1 could not allocate data structures, signals a serious problem with execution environment + 2 one or more input files were not well-formed + 3 could not create an output file + 4 command-line argument error xmlwf of libexpat is software libre, licensed under the MIT license. Please report bugs at https://github.com/libexpat/libexpat/issues -- thank you!