Bug 64273 - apr-util: apr_brigade_split_line leaves empty bucket when line ends with linefeed
Summary: apr-util: apr_brigade_split_line leaves empty bucket when line ends with line...
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR-util (show other bugs)
Version: 1.6.1
Hardware: All Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-27 11:52 UTC by Barnim Dzwillo
Modified: 2024-02-08 16:23 UTC (History)
0 users



Attachments
Bugfix for the described issue in apr-util-1.6.1 (631 bytes, patch)
2020-03-27 11:52 UTC, Barnim Dzwillo
Details | Diff
Bugfix for the described issue in apr-trunk (622 bytes, patch)
2020-03-27 11:53 UTC, Barnim Dzwillo
Details | Diff
Simple test program to demonstrate the issue (1.98 KB, text/x-csrc)
2020-03-27 11:54 UTC, Barnim Dzwillo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Barnim Dzwillo 2020-03-27 11:52:50 UTC
Created attachment 37128 [details]
Bugfix for the described issue in apr-util-1.6.1

Hello,

When the input for a apr_brigade_split_line() ends with a linefeed, an
empty bucket will be left in the input brigade when the last input line
was processed.

In many cases this will lead to extra work for the caller, because the
input brigade is not empty after the last line was processed.

For example the httpd code has extra checks to remove empty buckets from
a brigade in httpd/server/core_filters.c:ap_core_input_filter(), where
the call to BRIGADE_NORMALIZE(b) will trigger more often.
  
The attached patch fixes this issue for the current apr-util-1.6.1 library,
and the other patch fixes this for the apr-trunk library.

Also attached is a simple apr_splittest.c program to demonstrate the issue:

test "aa aa\n":
- output without patch:
     in bucket 00: start 6 length 0 IS_EMPTY!
    out bucket 00: start 0 length 6
- output with patch:
     in brigade empty
    out bucket 00: start 0 length 6

Greetings,
Barnim
Comment 1 Barnim Dzwillo 2020-03-27 11:53:26 UTC
Created attachment 37129 [details]
Bugfix for the described issue in apr-trunk
Comment 2 Barnim Dzwillo 2020-03-27 11:54:02 UTC
Created attachment 37130 [details]
Simple test program to demonstrate the issue
Comment 3 Joe Orton 2024-02-08 15:49:37 UTC
Thanks for the patch! Merged in r1915658 with some minor tweaks.
Comment 4 Joe Orton 2024-02-08 16:23:07 UTC
And r1915661 which actually added the patch