From: Michael Tremer Date: Wed, 3 Mar 2021 17:03:20 +0000 (+0000) Subject: util: Make pakfire_string_replace more robust on invalid inputs X-Git-Tag: 0.9.28~1285^2~648 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b961e8d5b7be47e4b3a53e4358b19d4073b9ff8e;p=pakfire.git util: Make pakfire_string_replace more robust on invalid inputs Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 70c04da6f..fe6ba5be8 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -74,6 +74,16 @@ PAKFIRE_EXPORT int pakfire_string_partition( PAKFIRE_EXPORT char* pakfire_string_replace( const char* s, const char* pattern, const char* repl) { + // Return NULL on no input or no pattern + if (!s || !pattern) { + errno = EINVAL; + return NULL; + } + + // Replace with nothing when repl is NULL + if (!repl) + repl = ""; + char* result = NULL; const char** cache = NULL; unsigned int count = 0;