mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 12:05:00 +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:
parent
0ee98c69c1
commit
8c5fa95ba3
1 changed files with 6 additions and 3 deletions
|
@ -426,7 +426,8 @@ static OwnPtr<Condition> parse_simple_expression(char* argv[])
|
||||||
|
|
||||||
// Try to read a unary op.
|
// Try to read a unary op.
|
||||||
if (arg.starts_with('-') && arg.length() == 2) {
|
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]) })) {
|
if (should_treat_expression_as_single_string({ argv[optind], strlen(argv[optind]) })) {
|
||||||
--optind;
|
--optind;
|
||||||
return make<StringCompare>(move(arg), ""sv, StringCompare::NotEqual);
|
return make<StringCompare>(move(arg), ""sv, StringCompare::NotEqual);
|
||||||
|
@ -571,10 +572,12 @@ static OwnPtr<Condition> parse_complex_expression(char* argv[])
|
||||||
} binary_operation { AndOp };
|
} binary_operation { AndOp };
|
||||||
|
|
||||||
if (arg == "-a") {
|
if (arg == "-a") {
|
||||||
optind++;
|
if (argv[++optind] == nullptr)
|
||||||
|
fatal_error("expected an expression");
|
||||||
binary_operation = AndOp;
|
binary_operation = AndOp;
|
||||||
} else if (arg == "-o") {
|
} else if (arg == "-o") {
|
||||||
optind++;
|
if (argv[++optind] == nullptr)
|
||||||
|
fatal_error("expected an expression");
|
||||||
binary_operation = OrOp;
|
binary_operation = OrOp;
|
||||||
} else {
|
} else {
|
||||||
// Ooops, looked too far.
|
// Ooops, looked too far.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue