Handle negative OOB access to local array in constant function (issue #674)

The word select expression is a zero-based canonical index, but the
expression evaluation may return a negative value.
This commit is contained in:
Martin Whitaker 2022-04-10 21:34:30 +01:00
parent 42de9e646a
commit 82caccd4eb
1 changed files with 3 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012-2021 Stephen Williams (steve@icarus.com) * Copyright (c) 2012-2022 Stephen Williams (steve@icarus.com)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU * and/or modify it in source code form under the terms of the GNU
@ -339,7 +339,7 @@ bool NetAssign::eval_func_lval_(const LineInfo&loc,
word = word_const->value().as_long(); word = word_const->value().as_long();
if (word >= var->nwords) if (word < 0 || word >= var->nwords)
return true; return true;
old_lval = var->array[word]; old_lval = var->array[word];
@ -999,7 +999,7 @@ NetExpr* NetESignal::evaluate_function(const LineInfo&loc,
int word = word_const->value().as_long(); int word = word_const->value().as_long();
if (word_const->value().is_defined() && (word < var->nwords)) if (word_const->value().is_defined() && (word >= 0) && (word < var->nwords))
value = var->array[word]; value = var->array[word];
} else { } else {
value = var->value; value = var->value;