From 7ab276972874fdcaeacdb458e0e52cd838200348 Mon Sep 17 00:00:00 2001 From: Philip Hazel Date: Sun, 28 Nov 2021 17:19:17 +0000 Subject: [PATCH] Check for NULL replacement in pcre2_substitute() --- ChangeLog | 2 ++ src/pcre2_substitute.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9e90b1..d558da3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,8 @@ substituting. 11. Add check for NULL subject to POSIX regexec() function. +12. Add check for NULL replacement to pcre2_substitute(). + Version 10.39 29-October-2021 ----------------------------- diff --git a/src/pcre2_substitute.c b/src/pcre2_substitute.c index 7aefb60..3d55d88 100644 --- a/src/pcre2_substitute.c +++ b/src/pcre2_substitute.c @@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2020 University of Cambridge + New API code Copyright (c) 2016-2021 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -261,9 +261,9 @@ if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0) return PCRE2_ERROR_BADOPTION; /* Validate length and find the end of the replacement. */ -if (replacement == NULL && rlength > 0) return PCRE2_ERROR_NULL; -else if (rlength == PCRE2_ZERO_TERMINATED) - rlength = PRIV(strlen)(replacement); + +if (replacement == NULL) return PCRE2_ERROR_NULL; +if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement); repend = replacement + rlength; /* Check for using a match that has already happened. Note that the subject