Fix pattern matching with invalid prefix.

pull/2229/head
Roger A. Light 4 years ago
parent 0cd2619401
commit b3045d1adf

@ -193,6 +193,7 @@ static int topic_matches_sub(const char *sub, const char *topic, const char *cli
{
size_t spos;
const char *pattern_check;
const char *lastchar = NULL;
if(!result) return MOSQ_ERR_INVAL;
*result = false;
@ -214,6 +215,7 @@ static int topic_matches_sub(const char *sub, const char *topic, const char *cli
return MOSQ_ERR_INVAL;
}
if(match_patterns &&
(lastchar == NULL || lastchar[0] == '/') &&
sub[0] == '%' &&
(sub[1] == 'c' || sub[1] == 'u') &&
(sub[2] == '/' || sub[2] == '\0')
@ -337,6 +339,7 @@ static int topic_matches_sub(const char *sub, const char *topic, const char *cli
return MOSQ_ERR_SUCCESS;
}
}
lastchar = sub-1;
}
if((topic[0] != 0 || sub[0] != 0)){
*result = false;

@ -411,6 +411,11 @@ static void TEST_pattern_both(void)
rc = mosquitto_topic_matches_sub_with_pattern("test/%username/%client", "test/username/clientid", "clientid", "username", &match);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
CU_ASSERT_EQUAL(match, false);
/* Not a pattern */
rc = mosquitto_topic_matches_sub_with_pattern("test/a%u/a%c", "test/ausername/aclientid", "clientid", "username", &match);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
CU_ASSERT_EQUAL(match, false);
}
static void TEST_pattern_wildcard(void)

Loading…
Cancel
Save