aboutsummaryrefslogtreecommitdiff
path: root/editors/awk.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'busybox' into mergeRon Yorston2024-07-101-63/+125
|\
| * 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>
* | Merge branch 'busybox' into mergeRon Yorston2024-06-231-4/+0
|\|
| * 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 segfault when compiled by clangRon Yorston2024-01-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. This patch has been submitted upstream. Until it's accepted there the new code is only used in builds for Windows.
* | Merge branch 'busybox' into mergeRon Yorston2024-01-051-16/+17
|\|
| * 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>
* | Merge branch 'busybox' into mergeFRP-5236-g7dff7f376Ron Yorston2023-12-051-49/+66
|\|
| * 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>
* | Merge branch 'busybox' into mergeRon Yorston2023-07-131-1/+1
|\|
| * Update applet size estimatesDenys Vlasenko2023-07-101-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2023-06-161-163/+246
|\|
| * 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: CRLF handlingRon Yorston2023-01-301-19/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previous efforts at handling DOS-style line endings in awk have included commits ee7e00dc5 and 1a3717342. The use of remove_cr() is unwise: - It's overzealous, removing all CRs, not just those in CRLF pairs. - Even if that were fixed awk reads input in chunks. There's a remote chance a CRLF might appear at a chunk boundary and be missed. remove_cr() will be fixed separately. In awk treat all data input as being in text mode. Skipping CRs in skip_spaces() is also flawed. Instead read scripts in text mode. Add a couple of test cases. One of these (awk backslash+CRLF eaten with no trace) fails without this patch.
* | awk: further improvements to randomnessRon Yorston2023-01-111-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | POSIX requires that the awk srand() function uses the time of day to seed the PRNG. The obvious implementation used in BusyBox does exactly that, passing time(NULL) to srand(3). When processes are started within a few seconds of one another their seeds are very similar. Given the realtively poor quality of rand(3) in some C runtimes this results in random number sequences that are somewhat correlated. Improve matters by using an integer hash on the seed, as recommended here: https://nullprogram.com/blog/2019/04/30/#the-wrong-places Costs 48 bytes. (GitHub issue #279)
* | awk: make random values more randomRon Yorston2023-01-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | When srand(3) is called to seed the random number generator with the current time the first value returned by rand(3) changes slowly with time. This is a property of the implementation in the C runtime. Change the order in which values from rand(3) are consumed to generate the value returned by the awk rand() function. This puts the value returned by the first call to rand(3) in the least significant bits, not the most significant. (GitHub issue #279)
* | Merge branch 'busybox' into mergeRon Yorston2022-10-121-0/+3
|\|
| * 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>
* | Merge busybox into mergeRon Yorston2022-01-131-7/+22
|\| | | | | | | | | | | | | Fix merge conflicts in coreutils/ls.c and shell/ash.c. Update config files to turn off SHA1_HWACCEL. It uses non-portable assembler.
| * 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>
* | Merge branch 'busybox' into mergeRon Yorston2021-09-101-16/+36
|\|
| * 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>
* | Merge branch 'busybox' into mergeRon Yorston2021-07-171-139/+177
|\|
| * 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>