Bug 64273

Summary: apr-util: apr_brigade_split_line leaves empty bucket when line ends with linefeed
Product: APR Reporter: Barnim Dzwillo <dzwillo>
Component: APR-utilAssignee: Apache Portable Runtime bugs mailinglist <bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 1.6.1   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Attachments: Bugfix for the described issue in apr-util-1.6.1
Bugfix for the described issue in apr-trunk
Simple test program to demonstrate the issue

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