+
Skip to content

fix xstrdup leak in parse_short_opt #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ TEST_BUILTINS_OBJS += test-online-cpus.o
TEST_BUILTINS_OBJS += test-pack-mtimes.o
TEST_BUILTINS_OBJS += test-parse-options.o
TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
TEST_BUILTINS_OBJS += test-free-unknown-options.o
TEST_BUILTINS_OBJS += test-partial-clone.o
TEST_BUILTINS_OBJS += test-path-utils.o
TEST_BUILTINS_OBJS += test-path-walk.o
Expand Down
17 changes: 16 additions & 1 deletion parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@ static int has_subcommands(const struct option *options)
return 0;
}

static void set_strdup_fn(struct parse_opt_ctx_t *ctx, const struct option *options) {
for (; options->type != OPTION_END; options++)
;
if (options->value && options->strdup_fn) {
ctx->unknown_opts = options->value;
ctx->strdup_fn = options->strdup_fn;
return;
}
}

static void parse_options_start_1(struct parse_opt_ctx_t *ctx,
int argc, const char **argv, const char *prefix,
const struct option *options,
Expand All @@ -655,6 +665,7 @@ static void parse_options_start_1(struct parse_opt_ctx_t *ctx,
ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
ctx->flags = flags;
ctx->has_subcommands = has_subcommands(options);
set_strdup_fn(ctx, options);
if (!ctx->has_subcommands && (flags & PARSE_OPT_SUBCOMMAND_OPTIONAL))
BUG("Using PARSE_OPT_SUBCOMMAND_OPTIONAL without subcommands");
if (ctx->has_subcommands) {
Expand Down Expand Up @@ -981,7 +992,11 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
*
* This is leaky, too bad.
*/
ctx->argv[0] = xstrdup(ctx->opt - 1);
if (ctx->unknown_opts && ctx->strdup_fn) {
ctx->argv[0] = ctx->strdup_fn(ctx->unknown_opts, ctx->opt - 1);
} else {
ctx->argv[0] = xstrdup(ctx->opt - 1);
}
*(char *)ctx->argv[0] = '-';
goto unknown;
case PARSE_OPT_NON_OPTION:
Expand Down
12 changes: 12 additions & 0 deletions parse-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
typedef int parse_opt_subcommand_fn(int argc, const char **argv,
const char *prefix, struct repository *repo);

typedef char *parse_opt_strdup_fn(void *value, const char *s);

/*
* `type`::
* holds the type of the option, you must have an OPTION_END last in your
Expand Down Expand Up @@ -165,6 +167,7 @@ struct option {
parse_opt_ll_cb *ll_callback;
intptr_t extra;
parse_opt_subcommand_fn *subcommand_fn;
parse_opt_strdup_fn *strdup_fn;
};

#define OPT_BIT_F(s, l, v, h, b, f) { \
Expand Down Expand Up @@ -388,6 +391,12 @@ static char *parse_options_noop_ignored_value MAYBE_UNUSED;
}
#define OPT_SUBCOMMAND(l, v, fn) OPT_SUBCOMMAND_F((l), (v), (fn), 0)

#define OPT_UNKNOWN(v, fn) { \
.type = OPTION_END, \
.value = (v), \
.strdup_fn = (fn), \
}

/*
* parse_options() will filter out the processed options and leave the
* non-option arguments in argv[]. argv0 is assumed program name and
Expand Down Expand Up @@ -496,6 +505,9 @@ struct parse_opt_ctx_t {
const char *prefix;
const char **alias_groups; /* must be in groups of 3 elements! */
struct parse_opt_cmdmode_list *cmdmode_list;

void *unknown_opts;
parse_opt_strdup_fn *strdup_fn;
};

void parse_options_start(struct parse_opt_ctx_t *ctx,
Expand Down
1 change: 1 addition & 0 deletions t/helper/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test_tool_sources = [
'test-pack-mtimes.c',
'test-parse-options.c',
'test-parse-pathspec-file.c',
'test-free-unknown-options.c',
'test-partial-clone.c',
'test-path-utils.c',
'test-path-walk.c',
Expand Down
35 changes: 35 additions & 0 deletions t/helper/test-free-unknown-options.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "git-compat-util.h"
#include "parse-options.h"
#include "setup.h"
#include "strvec.h"

static const char *const free_unknown_options_usage[] = {
"test-tool free-unknown-options",
NULL
};

int cmd__free_unknown_options(int argc, const char **argv) {

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / win build

t/helper/test-free-unknown-options.c:11:5: no previous prototype for 'cmd__free_unknown_options' [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for function 'cmd__free_unknown_options' [-Werror,-Wmissing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for 'cmd__free_unknown_options' [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for 'cmd__free_unknown_options' [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for 'cmd__free_unknown_options' [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for ‘cmd__free_unknown_options’ [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for function 'cmd__free_unknown_options' [-Werror,-Wmissing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for function 'cmd__free_unknown_options' [-Werror,-Wmissing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for 'cmd__free_unknown_options' [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for 'cmd__free_unknown_options' [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for ‘cmd__free_unknown_options’ [-Werror=missing-prototypes]

Check failure on line 11 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:11:5: no previous prototype for ‘cmd__free_unknown_options’ [-Werror=missing-prototypes]
struct strvec *unknown_opts = xmalloc(sizeof(struct strvec));
strvec_init(unknown_opts);
const char *prefix = setup_git_directory();

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / win build

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

t/helper/test-free-unknown-options.c:14:17: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

t/helper/test-free-unknown-options.c:14:17: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

t/helper/test-free-unknown-options.c:14:17: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 14 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:14:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

bool a, b;
struct option options[] = {
OPT_BOOL('a', "test-a", &a, N_("option a, only for test use")),
OPT_BOOL('b', "test-b", &b, N_("option b, only for test use")),
OPT_UNKNOWN(unknown_opts, (parse_opt_strdup_fn *)&strvec_push),
};

parse_options(argc, argv, prefix, options,
free_unknown_options_usage, PARSE_OPT_KEEP_UNKNOWN_OPT);

printf("a = %s\n", a? "true": "false");
printf("b = %s\n", b? "true": "false");

int i;

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / win build

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:29:5: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
for (i = 0; i < unknown_opts->nr; i++) {

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / win build

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long long unsigned int'} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

t/helper/test-free-unknown-options.c:30:19: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'unsigned int'} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

t/helper/test-free-unknown-options.c:30:19: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

t/helper/test-free-unknown-options.c:30:19: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]

Check failure on line 30 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:30:19: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
printf("free unknown option: %s\n", unknown_opts->v[i]);
}
strvec_clear(unknown_opts);
free(unknown_opts);
}

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / win build

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:1: non-void function does not return a value [-Werror,-Wreturn-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:2: no newline at end of file [-Werror,-Wnewline-eof]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora:latest)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / almalinux-8 (almalinux:8)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux32 (i386/ubuntu:focal)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:1: non-void function does not return a value [-Werror,-Wreturn-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-reftable (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:2: no newline at end of file [-Werror,-Wnewline-eof]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:1: non-void function does not return a value [-Werror,-Wreturn-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:2: no newline at end of file [-Werror,-Wnewline-eof]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu:20.04)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / debian-11 (debian:11)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-breaking-changes (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]

Check failure on line 35 in t/helper/test-free-unknown-options.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu:rolling)

t/helper/test-free-unknown-options.c:35:1: control reaches end of non-void function [-Werror=return-type]
1 change: 1 addition & 0 deletions t/helper/test-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static struct test_cmd cmds[] = {
{ "parse-options-flags", cmd__parse_options_flags },
{ "parse-pathspec-file", cmd__parse_pathspec_file },
{ "parse-subcommand", cmd__parse_subcommand },
{ "free-unknown-options", cmd__free_unknown_options},
{ "partial-clone", cmd__partial_clone },
{ "path-utils", cmd__path_utils },
{ "path-walk", cmd__path_walk },
Expand Down
1 change: 1 addition & 0 deletions t/helper/test-tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int cmd__parse_options(int argc, const char **argv);
int cmd__parse_options_flags(int argc, const char **argv);
int cmd__parse_pathspec_file(int argc, const char** argv);
int cmd__parse_subcommand(int argc, const char **argv);
int cmd__free_unknown_options(int argc, const char **argv);
int cmd__partial_clone(int argc, const char **argv);
int cmd__path_utils(int argc, const char **argv);
int cmd__path_walk(int argc, const char **argv);
Expand Down
14 changes: 14 additions & 0 deletions t/t0040-parse-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,18 @@ test_expect_success 'u16 limits range' '
test_grep "value 65536 for option .u16. not in range \[0,65535\]" err
'

cat >expect <<\EOF
a = true
b = true
free unknown option: -c
free unknown option: -d
EOF

test_expect_success 'free unknown options' '
test-tool free-unknown-options -ac -bd \
>output 2>output.err &&
test_cmp expect output &&
test_must_be_empty output.err
'

test_done
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载