aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-10-29 14:02:23 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-12-09 16:38:37 +0100
commit13fa009a2e103b46b7566d54f72d6229e54abf28 (patch)
tree52183a6b56484b7f5f729a6074466870863ab6cb
parent8600015b3e1597f5ce340ffaae9802fe7196f95f (diff)
downloadlibssh-13fa009a2e103b46b7566d54f72d6229e54abf28.tar.gz
libssh-13fa009a2e103b46b7566d54f72d6229e54abf28.tar.xz
libssh-13fa009a2e103b46b7566d54f72d6229e54abf28.zip
match: Avoid recursion with many asterisks in pattern
Partially fixes T186 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> (cherry picked from commit cf0beff987cc01e4ab0dd66cb1931c49511956c9)
-rw-r--r--src/match.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/match.c b/src/match.c
index 06587b92..5c85c7b0 100644
--- a/src/match.c
+++ b/src/match.c
@@ -38,6 +38,7 @@
#include "config.h"
#include <ctype.h>
+#include <stdbool.h>
#include <sys/types.h>
#include "libssh/priv.h"
@@ -46,7 +47,9 @@
* Returns true if the given string matches the pattern (which may contain ?
* and * as wildcards), and zero if it does not match.
*/
-static int match_pattern(const char *s, const char *pattern) {
+static int match_pattern(const char *s, const char *pattern)
+{
+ bool had_asterisk = false;
if (s == NULL || pattern == NULL) {
return 0;
}
@@ -57,16 +60,19 @@ static int match_pattern(const char *s, const char *pattern) {
return (*s == '\0');
}
- if (*pattern == '*') {
+ while (*pattern == '*') {
/* Skip the asterisk. */
+ had_asterisk = true;
pattern++;
+ }
+ if (had_asterisk) {
/* If at end of pattern, accept immediately. */
if (!*pattern)
return 1;
/* If next character in pattern is known, optimize. */
- if (*pattern != '?' && *pattern != '*') {
+ if (*pattern != '?') {
/*
* Look instances of the next character in
* pattern, and try to match starting from