awk negative field access

Denys Vlasenko vda.linux at googlemail.com
Mon Apr 23 08:54:01 UTC 2018


Applied, thanks!

On Sat, Apr 21, 2018 at 9:36 PM, Anthony DeDominic <anthony at dedominic.pw> wrote:
> It appears busybox v1.28.3 awk is not checking the bounds of field
> access:
>
>   busybox awk '{ print $(-1) }' <<< ''
>   0
>
> using a value high enough will make busybox segfault:
>
>   busybox awk '{ print $(-160) }' <<< ''
>   zsh: segmentation fault (core dumped)  busybox awk '{ print $(-160)
> }' <<< ''
>
> Other awks seem to check for negative field access:
>
>   gawk '{ print $(-1) }' <<< ''
>   gawk: cmd. line:1: (FILENAME=- FNR=1) fatal: attempt to access field
> -1
>
>   mawk '{ print $(-1) }' <<< ''
>   mawk: run time error: negative field index $-1
>         FILENAME="-" FNR=1 NR=1
>
>   nawk '{ print $(-1) }' <<< ''
>   nawk: trying to access out of range field -1
>     input record number 1, file
>     source line number 1
>
> Given how these other awks handle negative field access, this seems
> like a bug.
>
> I have a patch which appears to fix the issue, including a new test
> case.
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
>


More information about the busybox mailing list