aboutsummaryrefslogtreecommitdiff
path: root/editors/awk.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* awk: mktime() with no arguments is not allowedDenys Vlasenko2024-07-101-2/+1
| | | | | | It was SEGVing. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: improve comments and constants, no code changesDenys Vlasenko2024-07-101-20/+27
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* qwk: code shrinkDenys Vlasenko2024-07-091-19/+19
| | | | | | | | | | | | | function old new delta mk_splitter 100 96 -4 as_regex 103 99 -4 parse_expr 991 986 -5 awk_split 544 538 -6 awk_getline 559 552 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-26) Total: -26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: restore assignment precedence to be lower than ternary ?:Denys Vlasenko2024-07-091-11/+54
| | | | | | | Something is fishy with constrcts like "3==v=3" in gawk, they should not work, but do. Ignore those for now. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: do not infinitely recurse getvar_s() if CONVFMT is set to a numeric valueDenys Vlasenko2024-07-091-6/+14
| | | | | | | | | | | function old new delta fmt_num 247 257 +10 evaluate 3385 3379 -6 getvar_s 111 102 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-15) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix use after free (CVE-2023-42363)Natanael Copa2024-07-091-8/+13
| | | | | | | | | | function old new delta evaluate 3377 3385 +8 Fixes https://bugs.busybox.net/show_bug.cgi?id=15865 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix segfault when compiled by clangRon Yorston2024-03-021-1/+1
| | | | | | | | | | | | | | | | A 32-bit build of BusyBox using clang segfaulted in the test "awk assign while assign". Specifically, on line 7 of the test input where the adjustment of the L.v pointer when the Fields array was reallocated L.v += Fields - old_Fields_ptr; was out by 4 bytes. Rearrange to code so both gcc and clang generate code that works. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* awk: fix handling of empty fieldsDenys Vlasenko2023-12-311-16/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by M Rubon <rubonmtz@gmail.com>: Busybox awk handles references to empty (not provided in the input) fields differently during the first line of input, as compared to subsequent lines. $ (echo a ; echo b) | awk '$2 != 0' #wrong b No field $2 value is provided in the input. When awk references field $2 for the "a" line, it is seen to have a different behaviour than when it is referenced for the "b" line. Problem in BusyBox v1.36.1 embedded in OpenWrt 23.05.0 Same problem also in 21.02 versions of OpenWrt Same problem in BusyBox v1.37.0.git I get the correct expected output from Ubuntu gawk and Debian mawk, and from my fix. will@dev:~$ (echo a ; echo b) | awk '$2 != 0' #correct a b will@dev:~/busybox$ (echo a ; echo b ) | ./busybox awk '$2 != 0' #fixed a b I built and poked into the source code at editors/awk.c The function fsrealloc(int size) is core to allocating, initializing, reallocating, and reinitializing fields, both real input line fields and imaginary fields that the script references but do not exist in the input. When fsrealloc() needs more field space than it has previously allocated, it initializes those new fields differently than how they are later reinitialized for the next input line. This works fine for fields defined in the input, like $1, but does not work the first time when there is no input for that field (e.g. field $99) My one-line fix simply makes the initialization and clrvar() reinitialization use the same value for .type. I am not sure if there are regression tests to run, but I have not done those. I'm not sure if I understand why clrvar() is not setting .type to a default constant value, but in any case I have left that untouched. function old new delta ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: implement -E; do not reorder -f and -eDenys Vlasenko2023-10-021-48/+65
| | | | | | | | | | | | function old new delta awk_main 843 891 +48 next_input_file 243 261 +18 packed_usage 34631 34638 +7 .rodata 105391 105390 -1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 73/-1) Total: 72 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Update applet size estimatesDenys Vlasenko2023-07-101-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix subst code to handle "start of word" pattern correctly (needs ↵Denys Vlasenko2023-06-081-13/+36
| | | | | | | | | REG_STARTEND) function old new delta awk_sub 637 714 +77 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix SEGV on read error in -f PROGFILEDenys Vlasenko2023-06-071-2/+2
| | | | | | | function old new delta awk_main 829 843 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: code shrinkDenys Vlasenko2023-06-061-8/+10
| | | | | | | | | | function old new delta awk_sub 544 548 +4 exec_builtin 1136 1130 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-6) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix backslash handling in sub() builtinsDenys Vlasenko2023-06-031-22/+19
| | | | | | | function old new delta awk_sub 559 544 -15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix precedence of = relative to ==Denys Vlasenko2023-05-301-21/+45
| | | | | | | | | | | | Discovered while adding code to disallow assignments to non-lvalues function old new delta parse_expr 936 991 +55 .rodata 105243 105247 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0) Total: 59 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: printf(INVALID_FMT) prints it verbatimDenys Vlasenko2023-05-291-3/+9
| | | | | | | function old new delta awk_printf 628 640 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: shrink - use setvar_sn() to set variables from non-NUL terminated stringsDenys Vlasenko2023-05-281-14/+9
| | | | | | | | | | | function old new delta setvar_sn - 39 +39 exec_builtin 1145 1136 -9 awk_getline 591 559 -32 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 39/-41) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: code shrinkDenys Vlasenko2023-05-281-23/+24
| | | | | | | function old new delta awk_getline 620 591 -29 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix closing of non-opened fileDenys Vlasenko2023-05-281-8/+15
| | | | | | | | | | | | function old new delta setvar_ERRNO - 53 +53 .rodata 105252 105246 -6 awk_getline 639 620 -19 evaluate 3402 3377 -25 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 53/-50) Total: 3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: do not read ARGIND, only set it (gawk compat)Denys Vlasenko2023-05-271-5/+14
| | | | | | | | | | | function old new delta next_input_file 216 243 +27 evaluate 3396 3402 +6 awk_main 826 829 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0) Total: 36 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: remove a local variable "caching" a struct memberDenys Vlasenko2023-05-271-6/+4
| | | | | | | | | | Since we take its address, the variable lives on stack (not a GPR). Thus, nothing is improved by caching it. function old new delta awk_getline 642 639 -3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: get rid of one indirection level for iF (input file structure)Denys Vlasenko2023-05-271-37/+41
| | | | | | | | | | | | | function old new delta try_to_assign - 91 +91 next_input_file 214 216 +2 awk_main 827 826 -1 evaluate 3403 3396 -7 is_assignment 91 - -91 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/2 up/down: 93/-99) Total: -6 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix splitting with default FSDenys Vlasenko2023-05-271-5/+8
| | | | | | | function old new delta awk_split 543 544 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix use-after-realloc (CVE-2021-42380), closes 15601Denys Vlasenko2023-05-261-6/+20
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix use after free (CVE-2022-30065)Natanael Copa2022-07-111-0/+3
| | | | | | | | | | 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>
* awk: input numbers are never octal or hex (only program consts can be)Denys Vlasenko2022-01-081-7/+22
| | | | | | | | | | | | 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>
* awk: never return NULL from awk_printf()Denys Vlasenko2021-09-091-4/+4
| | | | | | | function old new delta awk_printf 651 628 -23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: code shrinkDenys Vlasenko2021-09-091-8/+7
| | | | | | | function old new delta awk_printf 652 651 -1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: code shrink: avoid duplicate NUL checks and strlen()Denys Vlasenko2021-09-091-21/+33
| | | | | | | function old new delta awk_printf 665 652 -13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix read beyond end of bufferRon Yorston2021-09-091-11/+13
| | | | | | | | | | | | | | | | | | | Commit 7d06d6e18 (awk: fix printf %%) can cause awk printf to read beyond the end of a strduped buffer: 2349 while (*f && *f != '%') 2350 f++; 2351 c = *++f; If the loop terminates because a NUL character is detected the character after the NUL is read. This can result in failures depending on the value of that character. function old new delta awk_printf 672 665 -7 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix printf %%Daniel Thau2021-09-051-1/+8
| | | | | | | | | | | | | | | | | A refactor of the awk printf code in e2e3802987266c98df0efdf40ad5da4b07df0113 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>
* awk: whitespace and debugging tweaksDenys Vlasenko2021-07-141-67/+66
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: disallow break/continue outside of loopsDenys Vlasenko2021-07-141-2/+4
| | | | | | | | | | 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>
* awk: tighten parsing - disallow extra semicolonsDenys Vlasenko2021-07-141-16/+24
| | | | | | | | | '; BEGIN {...}' and 'BEGIN {...} ;; {...}' are not accepted by gawk function old new delta parse_program 332 353 +21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: in parsing, remove superfluous NEWLINE check; optimize builtin arg ↵Denys Vlasenko2021-07-121-5/+6
| | | | | | | | | evaluation function old new delta exec_builtin 1149 1145 -4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix printf "%-10c", 0Denys Vlasenko2021-07-121-4/+5
| | | | | | | function old new delta awk_printf 596 626 +30 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix corner case in awk_printfDenys Vlasenko2021-07-111-4/+4
| | | | | | | | | | | Example where it wasn't working: awk 'BEGIN { printf "qwe %s rty %c uio\n", "a", 0, "c" }' - the NUL printing in %c caused premature stop of printing. function old new delta awk_printf 593 596 +3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: unbreak "cmd" | getlineDenys Vlasenko2021-07-111-1/+2
| | | | | | | function old new delta evaluate 3337 3343 +6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: unbreak "printf('%c') can output NUL" testcaseDenys Vlasenko2021-07-111-17/+26
| | | | | | | function old new delta awk_printf 546 593 +47 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: undo TI_PRINT, it introduced a bug (print with any redirect acting as ↵Denys Vlasenko2021-07-111-3/+5
| | | | | | | | | | | 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>
* awk: rollback_token() + chain_group() == chain_until_rbrace()Denys Vlasenko2021-07-111-2/+1
| | | | | | | function old new delta parse_program 336 332 -4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: fix printf buffer overflowDenys Vlasenko2021-07-041-39/+55
| | | | | | | | | | | | function old new delta awk_printf 468 546 +78 fmt_num 239 247 +8 getvar_s 125 111 -14 evaluate 3343 3329 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/2 up/down: 86/-28) Total: 58 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: simplify tests for operation classDenys Vlasenko2021-07-031-28/+36
| | | | | | | | | | | | | | | | | | | | | | | Usually, an operation class has only one possible value of "info" word. In this case, just compare the entire info word, do not bother to mask OPCLSMASK bits. (Example where this is not the case: OC_REPLACE for "<op>=") function old new delta mk_splitter 106 100 -6 chain_group 616 610 -6 nextarg 40 32 -8 exec_builtin 1157 1149 -8 as_regex 111 103 -8 awk_split 553 543 -10 parse_expr 948 936 -12 awk_getline 656 642 -14 evaluate 3387 3343 -44 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/9 up/down: 0/-116) Total: -116 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: restore strdup elision optimization in assignmentDenys Vlasenko2021-07-031-8/+17
| | | | | | | function old new delta evaluate 3339 3387 +48 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: match(): code shrinkDenys Vlasenko2021-07-031-13/+11
| | | | | | | | | | function old new delta do_match - 165 +165 exec_builtin_match 202 - -202 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/0 up/down: 165/-202) Total: -37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: rand(): 64-bit constants should be ULLDenys Vlasenko2021-07-031-2/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: do not use a copy of g_progname for node->l.new_prognameDenys Vlasenko2021-07-031-2/+2
| | | | | | | | | We never destroy g_progname's, the strings still exist, no need to copy function old new delta chain_node 104 97 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: support %F %a %A in printfDenys Vlasenko2021-07-031-1/+1
| | | | | | | function old new delta .rodata 104111 104120 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: open-code TS_OPTERM, no logic changesDenys Vlasenko2021-07-031-16/+17
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* awk: tighten rules in action parsingDenys Vlasenko2021-07-031-42/+66
| | | | | | | | | | | | | | | | | | Disallow: BEGIN { action } - must start on the same line Disallow: func f() print "hello" - must be in {...} function old new delta chain_until_rbrace - 41 +41 parse_program 307 336 +29 chain_group 649 616 -33 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 70/-33) Total: 37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>