diff options
author | 2007-03-10 23:51:51 -0800 | |
---|---|---|
committer | 2007-03-10 23:52:15 -0800 | |
commit | acc44bf36bdcb5753a26dec015a406b97f9b08b3 (patch) | |
tree | c6b4b300a1fc72651db052a40157e6b1dacbc295 /expand.c | |
parent | Remove stray space from expand_compare in expand.c (diff) | |
download | sparse-acc44bf36bdcb5753a26dec015a406b97f9b08b3.tar.gz sparse-acc44bf36bdcb5753a26dec015a406b97f9b08b3.tar.bz2 sparse-acc44bf36bdcb5753a26dec015a406b97f9b08b3.zip |
Prevent potential NULL pointer dereference in expand_compare
expand_compare could dereference left->ctype without checking that left !=
NULL. Fix that, by extending the check for (left && right) around most of the
function.
Thanks to Florian Krohm of IBM for reporting the problem.
Signed-off-by: Josh Triplett <josh@freedesktop.org>
Diffstat (limited to 'expand.c')
-rw-r--r-- | expand.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -463,17 +463,19 @@ static int expand_compare(struct expression *expr) cost = expand_expression(left); cost += expand_expression(right); - /* Type comparison? */ - if (left && right && left->type == EXPR_TYPE && right->type == EXPR_TYPE) { - int op = expr->op; - expr->type = EXPR_VALUE; - expr->value = compare_types(op, left->symbol, right->symbol); - return 0; + if (left && right) { + /* Type comparison? */ + if (left->type == EXPR_TYPE && right->type == EXPR_TYPE) { + int op = expr->op; + expr->type = EXPR_VALUE; + expr->value = compare_types(op, left->symbol, right->symbol); + return 0; + } + if (simplify_cmp_binop(expr, left->ctype)) + return 0; + if (simplify_float_cmp(expr, left->ctype)) + return 0; } - if (simplify_cmp_binop(expr, left->ctype)) - return 0; - if (simplify_float_cmp(expr, left->ctype)) - return 0; return cost + 1; } |