Commit Graph

55 Commits

Author SHA1 Message Date
Natanael Copa
e63d7cdfda awk: fix use after free (CVE-2022-30065)
fixes https://bugs.busybox.net/show_bug.cgi?id=14781

function                                             old     new   delta
evaluate                                            3343    3357     +14

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-07-11 17:18:07 +02:00
Denys Vlasenko
e2952dfaff awk: input numbers are never octal or hex (only program consts can be)
function                                             old     new   delta
next_token                                           825     930    +105
getvar_i                                             114     129     +15
nextchar                                              49      53      +4
my_strtod                                            138       -    -138
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/0 up/down: 124/-138)          Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-08 22:42:35 +01:00
Daniel Thau
7d06d6e186 awk: fix printf %%
A refactor of the awk printf code in
e2e3802987
appears to have broken the printf interpretation of two percent signs,
which normally outputs only one percent sign.

The patch below brings busybox awk printf behavior back into alignment
with the pre-e2e380 behavior, the busybox printf util, and other common
(awk and non-awk) printf implementations.

function                                             old     new   delta
awk_printf                                           626     672     +46

Signed-off-by: Daniel Thau <danthau at bedrocklinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-05 03:42:51 +02:00
Denys Vlasenko
8e8cea2a1b awk: fix testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-16 07:37:22 +02:00
Denys Vlasenko
d3480dd582 awk: disallow break/continue outside of loops
function                                             old     new   delta
.rodata                                           104139  104186     +47
chain_group                                          610     633     +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 70/0)               Total: 70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-14 16:32:19 +02:00
Denys Vlasenko
8d269ef859 awk: fix printf "%-10c", 0
function                                             old     new   delta
awk_printf                                           596     626     +30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-12 11:27:11 +02:00
Denys Vlasenko
39aabfe8f0 awk: unbreak "cmd" | getline
function                                             old     new   delta
evaluate                                            3337    3343      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-11 12:51:43 +02:00
Denys Vlasenko
3d57a84907 awk: undo TI_PRINT, it introduced a bug (print with any redirect acting as printf)
function                                             old     new   delta
evaluate                                            3329    3337      +8

Patch by Ron Yorston <rmy@pobox.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-11 12:00:31 +02:00
Denys Vlasenko
4d902ea9de awk: fix beavior of "exit" without parameter
function                                             old     new   delta
evaluate                                            3336    3339      +3
awk_exit                                              93      94      +1
awk_main                                             829     827      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 4/-2)                Total: 2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-02 22:28:51 +02:00
Denys Vlasenko
d7354df169 awk: evaluate all, even superfluous function args
function                                             old     new   delta
evaluate                                            3128    3135      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-30 12:52:51 +02:00
Denys Vlasenko
d150710169 awk: allow empty fuinctions with no arguments, disallow function redefinitions
function                                             old     new   delta
.rodata                                           103681  103700     +19
parse_program                                        303     307      +4
evaluate                                            3145    3141      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 23/-4)              Total: 19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-30 12:23:51 +02:00
Denys Vlasenko
6872c193a9 awk: fix parsing of expressions such as "v (a)"
function                                             old     new   delta
next_token                                           812     825     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-29 12:16:36 +02:00
Ron Yorston
e8fe9f9635 awk: allow printf('%c') to output NUL, closes 13486
Treat the output of printf as binary rather than a null-terminated
string so that NUL characters can be output.

This is considered to be a GNU extension, though it's also available
in mawk and FreeBSD's awk.

function                                             old     new   delta
evaluate                                            3487    3504     +17
awk_printf                                           504     519     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0)               Total: 32 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-02-02 13:51:14 +01:00
Denys Vlasenko
758c2bd58e awk: add a test that $NF is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-04 19:00:06 +01:00
Denys Vlasenko
665a659530 awk: FS regex matches only non-empty separators (gawk compat)
function                                             old     new   delta
awk_split                                            484     553     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-02 19:07:31 +01:00
Denys Vlasenko
6f7a009649 awk: disallow "str"++, closes bug 12981
function                                             old     new   delta
parse_expr                                           887     896      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-06-09 01:33:54 +02:00
Denys Vlasenko
bd8b05ba1b awk: fix more "length" cases, closes 12486
function                                             old     new   delta
next_token                                           808     831     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-02 23:28:55 +01:00
Denys Vlasenko
22cc92833f awk: fix testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-08 13:00:46 +02:00
Brian Foley
1c42c18e96 awk: Fix overly permissive func arg list parsing
It allows things like 'func f(a b)' and 'func f(a,)' which GNU awk forbids.

function                                             old     new   delta
parse_program                                        327     367     +40
chain_expr                                            40      67     +27
parse_expr                                           891     915     +24
EMSG_TOO_FEW_ARGS                                     30      18     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 91/-12)             Total: 79 bytes

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-21 12:59:19 +01:00
Brian Foley
08a514c097 awk: Syntax error if delete isn't given an arg.
Unlike exit and return, delete strictly requires an arg, and derefs a
null pointer if executed without one.

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-21 12:55:49 +01:00
Brian Foley
dac15a10ac awk: Guard pointer chasing when parsing ternary expressions.
Avoids an uninit pointer deref for some malformed ternary exprs.

Add a test that would crash in busybox before this fix.

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-21 12:55:49 +01:00
Denys Vlasenko
2454e678cb awk: do not allow $(-1)
function                                             old     new   delta
EMSG_NEGATIVE_FIELD                                    -      25     +25
evaluate                                            3390    3403     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 38/0)               Total: 38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-23 10:53:18 +02:00
Denys Vlasenko
6f4a785bd1 awk: fix 'delete array[var--]' decrementing var twice
function                                             old     new   delta
evaluate                                            3395    3390      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-07 01:19:08 +01:00
Brian Foley
61d5997b58 awk: fix segfault on for loop syntax error
Parsing "for()" segfaults as awk fails to find loop iteration expressions.

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24 02:09:56 +02:00
Denys Vlasenko
28b00ce6ff awk: support "length" form of "length()". Closes 8371
function                                             old     new   delta
parse_expr                                           805     848     +43
tokenlist                                            447     448      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-02 02:41:39 +02:00
Denys Vlasenko
5f8daefb83 awk: fix handling of "if ... break ; else ..." - closes 7226
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-26 16:40:28 +02:00
Denys Vlasenko
198b02f7dd fix failures found by randomconfig builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-12-31 23:22:36 +01:00
Denys Vlasenko
bd0e221620 awk: fix a bug in argc counting in recent change
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-11-21 15:09:55 +01:00
Denys Vlasenko
7985bc109e awk: fix length(array)
function                                             old     new   delta
evaluate                                            3526    3548     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-10-12 04:51:54 +02:00
Bernhard Reutner-Fischer
a060a1ad96 awk: Fix handling of functions with empty body
ammend b79a0fef99 to properly
handle functions defined in another scope.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-07-31 21:51:14 +02:00
Denys Vlasenko
b855460adc awk.tests: add test for recent large integer fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-07-22 11:49:06 +02:00
Bernhard Reutner-Fischer
b79a0fef99 awk: Fix handling of functions with empty body
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-13 09:47:07 +01:00
Denys Vlasenko
df8066a78c awk: fix FS assignment behavior. Closes 5108
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-07-11 01:27:15 +02:00
Denys Vlasenko
ea664dde87 awk: make -F STR interpret escape sequences. Closes 5126
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-06-22 18:41:01 +02:00
Tanguy Pruvot
0a393cf7da testsuite: some more awk tests related to conditions
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-06-11 10:33:45 +02:00
Denys Vlasenko
7b46d11582 awk: fix a SEGV
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-11 00:30:56 +02:00
Denys Vlasenko
6a0d7490ea awk: fix segfault on closing non-opened file
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-10-23 21:02:15 +02:00
Denys Vlasenko
d527e0c81d awk: 00.123 is not a octal constant; neither is 009.123. fixing this
function                                             old     new   delta
my_strtod                                             80     113     +33

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-10-05 13:22:11 +02:00
Denys Vlasenko
0ef64bdb40 *: make GNU licensing statement forms more regular
This change retains "or later" state! No licensing _changes_ here,
only form is adjusted (article, space between "GPL" and "v2" and so on).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-08-16 20:14:46 +02:00
Denys Vlasenko
bfa1b2e8e8 randomtest fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-11 03:53:57 +02:00
Denys Vlasenko
8e3aff0ce0 more randomconfig testsuite fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-10 11:00:11 +02:00
Denys Vlasenko
e3d90a90d4 randomconfig testsuite fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-05-10 05:53:16 +02:00
Denys Vlasenko
90f19fa468 awk: add two tests we currently fail
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-11 08:27:53 +01:00
Denys Vlasenko
3cb60c3973 awk: fix the case where nested "for" loops with the same variable misbehave
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-03-10 19:20:32 +01:00
Alexander Shishkin
d03cd3be24 awk: skip whitespace between array name and subscript
It is supported in both mawk and gawk and there are actually scripts
out there that use this "flexibility".

function                                             old     new   delta
next_token                                          1144    1152      +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0)                 Total: 8 bytes

Signed-off-by: Alexander Shishkin <virtuoso@slind.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-02-26 08:48:56 +01:00
Denys Vlasenko
1284774d60 awk: fix an incorrect casting to string (bug 725). -44 bytes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-11-30 01:15:04 +01:00
Mike Frysinger
caa79406aa tests: fix POSIX shell source style
The source command does not search $PWD, and bash recently fixed itself to
follow this behavior for /bin/sh.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-11-04 18:41:22 -05:00
Denis Vlasenko
67b5eeb933 awk: fix long field separators case. By Ian Wienand (ianw AT vmware.com) 2009-04-12 13:54:13 +00:00
Denis Vlasenko
7a6766428e awk: fix compat issue found by gpm build
function                                             old     new   delta
as_regex                                             105     131     +26
hash_find                                            247     233     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 26/-14)             Total: 12 bytes
2009-03-15 22:20:31 +00:00
Denis Vlasenko
41d5ebee17 awk: in BEGIN section $0 should be "", not "0". 2009-01-25 01:00:15 +00:00