Skip to content

Commit

Permalink
lttng2.ust.core: reduce backtracking and clean up regex
Browse files Browse the repository at this point in the history
Make sure the regex used here, which is vulnerable to polynomial runtime
due to backtracking, cannot lead to denial of service.

Change-Id: I1f89b65baba8f8bb6b66dc6d0dbdb062017ee995
Signed-off-by: Sehr Moosabhoy <sehr.moosabhoy@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/202168
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
Sehr Moosabhoy authored and MatthewKhouzam committed Jun 5, 2023
1 parent 4279634 commit 1e09a7c
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class UstDebugInfoStateProvider extends AbstractTmfStateProvider {
*
* <value> <type> <name> <source>:<line>
*/
private static final Pattern fNmPattern = Pattern.compile("(\\w+)(\\s+)(\\w)(\\s{1,})([^\\t]*)(\\t*)([^\\:]*)(:*)(.*)"); //$NON-NLS-1$
private static final Pattern fNmPattern = Pattern.compile("^\\s*(\\S++)\\s++(\\w)\\s++(\\S++)\\s++([^\\:\\s]*):(.*)$"); //$NON-NLS-1$

private final LttngUst28EventLayout fLayout;
private final Map<String, Integer> fEventNames;
Expand Down Expand Up @@ -660,10 +660,10 @@ private static void getNmInfo(ITmfStateSystemBuilder ssb, String binFilePath) {
Matcher nmLineMatcher = fNmPattern.matcher(nmLine);
if (nmLineMatcher.matches()) {
String offset = nmLineMatcher.group(1).replaceFirst("^0+(?!$)", ""); //$NON-NLS-1$ //$NON-NLS-2$
String functionName = nmLineMatcher.group(5);
String functionName = nmLineMatcher.group(3);
if ((offset != null) && (functionName != null)) {
String sourceFile = nmLineMatcher.group(7);
String lineNr = nmLineMatcher.group(9);
String sourceFile = nmLineMatcher.group(4);
String lineNr = nmLineMatcher.group(5);
// push in ss
int funNameQuark = ssb.getQuarkAbsoluteAndAdd(binFilePath, FUNCTION_NAME);
int sourceFileQuark = ssb.getQuarkAbsoluteAndAdd(binFilePath, SOURCE_FILE_NAME);
Expand Down

0 comments on commit 1e09a7c

Please sign in to comment.