Bug 60413 - RewriteValve: empty capturing group results in null backreference instead of "" (empty string)
Summary: RewriteValve: empty capturing group results in null backreference instead of ...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.5.x-trunk
Hardware: All All
: P2 major (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-24 09:47 UTC by Michael Osipov
Modified: 2016-11-28 14:06 UTC (History)
0 users



Attachments
Avoid null return values (1.79 KB, patch)
2016-11-24 09:47 UTC, Michael Osipov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Osipov 2016-11-24 09:47:21 UTC
Created attachment 34474 [details]
Avoid null return values

Consider this rule:
RewriteRule ^/docs(/rest)?$ /docs$1/ [redirect=307,L]

A GET on http://localhost:8080/app/docs redirects to http://localhost:8080/tedab-services-webapp/docsnull/

The reason is m.group(n) returns a null when the capturing group is not present. Worse than that, this null value is passed to ENCODER.encode() which may result in a NPE.

Attached is a patched which resolves the issue by returning empty strings on null. Feel free to improve the patch.
Comment 1 Mark Thomas 2016-11-28 14:06:44 UTC
Thanks for the report and the patch.

Fixed in:
- trunk for 9.0.0.M14 onwards
- 8.5.x for 8.5.9 onwards
- 8.0.x for 8.0.40 onwards

The patch was applied with the addition of a simple test case.