diff options
| author | Ben Winston | 2024-06-07 21:42:53 -0400 |
|---|---|---|
| committer | Ben Winston | 2024-06-07 21:42:53 -0400 |
| commit | ea9226df0bd7e820d1dbcad839265f1d5c4a8ff7 (patch) | |
| tree | 5f7243b20d96ca857e14d92a5498d3da1d415484 | |
| parent | ae60a8385a97689a61680b49400d70d553cfb299 (diff) | |
prevent null dereference on bad search term
| -rw-r--r-- | booki.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -765,6 +765,11 @@ struct search_opt parse_search_options(int argc, char* argv[]) { edit = true; break; case '?': + if (!argv[optind] || argv[optind][0] == '-') { + printf("%s requires an operand\n", argv[optind-1]); + opt_out.count = -1; + return opt_out; + } // optind points at the argument (one past the option) opt_out.opts[count] = argv[optind-1] + 2; // '--example' -> 'example' opt_out.args[count] = argv[optind]; @@ -786,6 +791,9 @@ struct search_opt parse_search_options(int argc, char* argv[]) { void search(int argc, char* argv[], char* booki_file) { struct search_opt search_opts = parse_search_options(argc, argv); + if (search_opts.count == -1) { + return; + } // get the books array char* data = load_file(booki_file); |
