Bug 153659 - awk(1) segfaults when trying to extract a combination of special characters
Summary: awk(1) segfaults when trying to extract a combination of special characters
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-03 20:00 UTC by Olivier
Modified: 2021-07-20 01:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier 2011-01-03 20:00:29 UTC
awk seg faults when it has to deal with at least one sequence of characters.
This makes it crash: %*
I don't know if it happens with other combinations

Fix: 

I'm not aware of any fixes
How-To-Repeat: # edit conf
Type this
GPG_PW='%*'

# edit awk_test.sh
Type this
awk '/^[ \t]*GPG_PW[ \t=]/{\
        sub(/^[ \t]*GPG_PW[ \t]*=*/,"",$0);\
        gsub(/^[ \t]*[\047"]|[\047"][ \t]*$/,"",$0);\
        printf $0; exit}' "$1"


Now try to extract GPG_PW
# ./awk_test.sh conf

You will get this:
./awk_test.sh: line 4: 18676 Segmentation fault: 11  (core dumped) awk '/^[ \t]*GPG_PW[ \t=]/{\
        sub(/^[ \t]*GPG_PW[ \t]*=*/,"",$0);\
        gsub(/^[ \t]*[\047"]|[\047"][ \t]*$/,"",$0);\
        printf $0; exit}' "$1"
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2011-01-04 02:50:50 UTC
Responsible Changed
From-To: freebsd-amd64->freebsd-bugs

reclassify.
Comment 2 Pedro F. Giffuni 2011-01-06 17:29:35 UTC
FWIW;

This didn't segfault on i386 (8.2-RC1).

Perhaps you could try the lang/nawk port?
It's a more recent version than the awk
in base.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:07 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 4 Warner Losh freebsd_committer freebsd_triage 2021-07-20 01:43:38 UTC
This awk program is incorrect (the printf uses the input line, but doesn't have enough args).
awk properly detects this now and does not segfault, but issues the following diagnostic:
awk: not enough args in printf(%*)
 input record number 1, file conf
 source line number 1