diff options
author | implicitfield <114500360+implicitfield@users.noreply.github.com> | 2022-10-02 23:45:06 +0300 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-10-11 23:38:13 -0600 |
commit | 8c5fa95ba351c690b6cd0a1d8edfc8a2314ce46c (patch) | |
tree | cb0333e09114871754442c62ea5d865d7ee4c662 | |
parent | 0ee98c69c1a295eba047037bccf9515230c01483 (diff) | |
download | serenity-8c5fa95ba351c690b6cd0a1d8edfc8a2314ce46c.zip |
test: Guard code paths that may lead to a null pointer dereference
test no longer crashes with a segmentation violation if invalid
arguments are passed.
-rw-r--r-- | Userland/Utilities/test.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Utilities/test.cpp b/Userland/Utilities/test.cpp index 5f0bd44fe7..a0423615cf 100644 --- a/Userland/Utilities/test.cpp +++ b/Userland/Utilities/test.cpp @@ -426,7 +426,8 @@ static OwnPtr<Condition> parse_simple_expression(char* argv[]) // Try to read a unary op. if (arg.starts_with('-') && arg.length() == 2) { - optind++; + if (argv[++optind] == nullptr) + fatal_error("expected an argument"); if (should_treat_expression_as_single_string({ argv[optind], strlen(argv[optind]) })) { --optind; return make<StringCompare>(move(arg), ""sv, StringCompare::NotEqual); @@ -571,10 +572,12 @@ static OwnPtr<Condition> parse_complex_expression(char* argv[]) } binary_operation { AndOp }; if (arg == "-a") { - optind++; + if (argv[++optind] == nullptr) + fatal_error("expected an expression"); binary_operation = AndOp; } else if (arg == "-o") { - optind++; + if (argv[++optind] == nullptr) + fatal_error("expected an expression"); binary_operation = OrOp; } else { // Ooops, looked too far. |