Bug 11871 - Bug in sed addressing (<addr>,+N)
Summary: Bug in sed addressing (<addr>,+N)
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.30.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-13 06:44 UTC by vit.lapka
Modified: 2019-05-13 14:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Patch that seems to fix the issue (656 bytes, patch)
2019-05-13 06:44 UTC, vit.lapka
Details
Busybox config file (33.26 KB, application/octet-stream)
2019-05-13 06:50 UTC, vit.lapka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vit.lapka 2019-05-13 06:44:53 UTC
Created attachment 8036 [details]
Patch that seems to fix the issue

Hello,
  it seems I have found a bug in busybox implementation of sed utility (version 1.29.3, also in 1.30.1). When using row addressing in sed command in format <addr1>,+N (i.e. apply to N rows following the match of <addr1>), it seems that following rows are processed only for the first match. For following matches, only the first row (matching <addr1>) is processed.
  Example:
- test file:
AAA
    BBB1
CCC
CCC
AAA
    BBB2
AAA
    BBB3
- command: sed -n '/AAA/,+1 p' file
- expected result (GNU sed):
AAA
    BBB1
AAA
    BBB2
AAA
    BBB3
- busybox sed:
AAA
    BBB1
AAA
AAA
  I have just quickly inspected the code and it seems that index of the last line for multiline match is overwritten with computed value relative to the first match and not reset/recomputed for further matches. I created a patch that seems to fix the issue, however I am not entirely confident it is a correct and clean solution.
With regards,
  Vit Lapka
Comment 1 vit.lapka 2019-05-13 06:50:17 UTC
Created attachment 8041 [details]
Busybox config file
Comment 2 Denys Vlasenko 2019-05-13 14:31:12 UTC
Fixed in git, thanks!