[PATCH 1/9] bc: Fix condition for reference

Steve Capper steve.capper at arm.com
Mon Apr 4 10:49:54 UTC 2022


From: Tudor Cretu <tudor.cretu at arm.com>

A reference can be either an array of numbers or an array of arrays.
The bc code makes the following check for a reference:
    ref = (v->size == sizeof(BcVec) && t != BC_TYPE_ARRAY);

Which, semantically, only checks for an array of arrays. On many
platforms, one has sizeof(BcVec) == sizeof(BcNum); and the above check
implicitly covers an array of numbers too.

Unfortunately, there are cases where sizeof(BcVec) != sizeof(BcNum) (the
Morello platform being one), which can lead to an array of numbers being
mis-identified. (Any future changes to the two structs could also lead
to their sizes changing).

This patch fixes the conditional check to cover both array of arrays and
array of numbers explicitly.

Signed-off-by: Tudor Cretu <tudor.cretu at arm.com>
Reviewed-by: Steve Capper <steve.capper at arm.com>
[SteveC: tweaked commit log]
Signed-off-by: Steve Capper <steve.capper at arm.com>
---
 miscutils/bc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/miscutils/bc.c b/miscutils/bc.c
index ab785bbc8..55f23cfb6 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -5921,7 +5921,7 @@ static BC_STATUS zxc_program_popResultAndCopyToVar(char *name, BcType t)
 		BcVec *v = (BcVec*) n;
 		bool ref, ref_size;
 
-		ref = (v->size == sizeof(BcVec) && t != BC_TYPE_ARRAY);
+		ref = ((v->size == sizeof(BcVec) || v->size == sizeof(BcNum)) && t != BC_TYPE_ARRAY);
 		ref_size = (v->size == sizeof(uint8_t));
 
 		if (ref || (ref_size && t == BC_TYPE_REF)) {
-- 
2.35.1



More information about the busybox mailing list