1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

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.
This commit is contained in:
implicitfield 2022-10-02 23:45:06 +03:00 committed by Andrew Kaster
parent 0ee98c69c1
commit 8c5fa95ba3

View file

@ -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.