Bug 15051 - [PATCH] Awk: fix bitwise functions result/arguments truncation on 32bit platforms
Summary: [PATCH] Awk: fix bitwise functions result/arguments truncation on 32bit platf...
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-09 11:54 UTC by Carlos Ibáñez
Modified: 2022-10-09 11:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
awk-bitwise-fix-arch32.patch (752 bytes, patch)
2022-10-09 11:54 UTC, Carlos Ibáñez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Ibáñez 2022-10-09 11:54:05 UTC
Created attachment 9386 [details]
awk-bitwise-fix-arch32.patch

Hi!

On platforms that use 32bit longs data is lost when performing bitwise operations if the result and/or arguments are equal-to/greater-than 2^32.

This behavior is unexpected as Busybox Awk numbers are doubles[1] (typically up to 2^53) and this issue is not present on GNU Awk.

Example 1 - Result equal-to/greater-than 2^32:

  awk 'BEGIN{print lshift(1, 32)}'

It returns 1, instead of the expected 4294967296.


Example 2 - Arguments equal-to/greater-than 2^32:

  awk 'BEGIN{print and(2^32, 2^32)}'

It returns 0, instead of the expected 4294967296.


The patch attached simply changes the castings and type of the getvar_i_int function from long to long long.

Note that the patch found in bug 15036[3] adds two functions that operate/return long numbers that shall also be changed into long long when accepted.

Cheers,
Carlos


[1] - https://git.busybox.net/busybox/tree/editors/awk.c?id=c8c1fcdba163f264a503380bc63485aacd09214c#n123
[2] - https://git.busybox.net/busybox/tree/editors/awk.c?id=c8c1fcdba163f264a503380bc63485aacd09214c#n1048
[3] - https://bugs.busybox.net/show_bug.cgi?id=15036