1
0
mirror of https://github.com/eclipse/mosquitto.git synced 2025-05-09 01:01:11 +08:00

Merge branch 'fix2908' of github.com:ckrey/mosquitto into ckrey-fix2908

This commit is contained in:
Roger A. Light 2025-02-25 12:34:41 +00:00
commit a8d887f30b
5 changed files with 137 additions and 125 deletions

View File

@ -70,7 +70,7 @@ int mosquitto_pub_topic_check(const char *str)
len++;
str = &str[1];
}
if(len > 65535) return MOSQ_ERR_INVAL;
if(len == 0 || len > 65535) return MOSQ_ERR_INVAL;
#ifdef WITH_BROKER
if(hier_count > TOPIC_HIERARCHY_LIMIT) return MOSQ_ERR_INVAL;
#endif
@ -85,7 +85,7 @@ int mosquitto_pub_topic_check2(const char *str, size_t len)
int hier_count = 0;
#endif
if(str == NULL || len > 65535){
if(str == NULL || len == 0 || len > 65535){
return MOSQ_ERR_INVAL;
}
@ -144,7 +144,7 @@ int mosquitto_sub_topic_check(const char *str)
c = str[0];
str = &str[1];
}
if(len > 65535) return MOSQ_ERR_INVAL;
if(len == 0 || len > 65535) return MOSQ_ERR_INVAL;
#ifdef WITH_BROKER
if(hier_count > TOPIC_HIERARCHY_LIMIT) return MOSQ_ERR_INVAL;
#endif
@ -160,7 +160,7 @@ int mosquitto_sub_topic_check2(const char *str, size_t len)
int hier_count = 0;
#endif
if(str == NULL || len > 65535){
if(str == NULL || len == 0 || len > 65535){
return MOSQ_ERR_INVAL;
}

View File

@ -59,10 +59,12 @@ static int bridge__create_prefix(char **full_prefix, const char *topic, const ch
{
size_t len;
if(!prefix || strlen(prefix) != 0){
if(mosquitto_pub_topic_check(prefix) != MOSQ_ERR_SUCCESS){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic local prefix '%s'.", prefix);
return MOSQ_ERR_INVAL;
}
}
if(topic){
len = strlen(topic) + strlen(prefix) + 1;

View File

@ -100,7 +100,6 @@ int handle__subscribe(struct mosquitto *context)
return MOSQ_ERR_MALFORMED_PACKET;
}
if(sub){
if(!slen){
log__printf(NULL, MOSQ_LOG_INFO,
"Empty subscription string from %s, disconnecting.",
@ -189,6 +188,7 @@ int handle__subscribe(struct mosquitto *context)
break;
default:
mosquitto__free(sub);
mosquitto__free(payload);
return rc2;
}
@ -196,6 +196,7 @@ int handle__subscribe(struct mosquitto *context)
rc2 = sub__add(context, sub, qos, subscription_identifier, subscription_options);
if(rc2 > 0){
mosquitto__free(sub);
mosquitto__free(payload);
return rc2;
}
if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt31){
@ -225,11 +226,11 @@ int handle__subscribe(struct mosquitto *context)
return MOSQ_ERR_NOMEM;
}
}
}
if(context->protocol != mosq_p_mqtt31){
if(payloadlen == 0){
/* No subscriptions specified, protocol error. */
fprintf(stderr, "no payload\n");
return MOSQ_ERR_MALFORMED_PACKET;
}
}

View File

@ -17,6 +17,9 @@ def write_config(filename, port1, port2, protocol_version):
f.write("topic +/value in 0 local3/topic/ remote3/topic/\n")
f.write("topic ic/+ in 0 local4/top remote4/tip\n")
f.write("topic clients/total in 0 test/mosquitto/org $SYS/broker/\n")
f.write('topic rmapped in 0 "" remote/mapped/\n')
f.write('topic lmapped in 0 local/mapped/ ""\n')
f.write('topic "" in 0 local/single remote/single\n')
f.write("notifications false\n")
f.write("restart_timeout 5\n")
f.write("bridge_protocol_version %s\n" % (protocol_version))
@ -70,6 +73,9 @@ def inner_test(bridge, sock, proto_ver):
('local3/topic/something/value', 'remote3/topic/something/value'),
('local4/topic/something', 'remote4/tipic/something'),
('test/mosquitto/orgclients/total', '$SYS/broker/clients/total'),
('local/mapped/lmapped', 'lmapped'),
('rmapped', 'remote/mapped/rmapped'),
('local/single', 'remote/single'),
]
for (local_topic, remote_topic) in cases:

View File

@ -196,6 +196,7 @@ static void TEST_invalid(void)
no_match_helper(MOSQ_ERR_INVAL, "foo/#abc", "foo");
no_match_helper(MOSQ_ERR_INVAL, "#abc", "foo");
no_match_helper(MOSQ_ERR_INVAL, "/#a", "foo/bar");
no_match_helper(MOSQ_ERR_INVAL, "", "foo/bar/#");
}
/* ========================================================================
@ -233,6 +234,7 @@ static void TEST_pub_topic_invalid(void)
pub_topic_helper("pub/topic#", MOSQ_ERR_INVAL);
pub_topic_helper("pub/topic/#", MOSQ_ERR_INVAL);
pub_topic_helper("+/pub/topic", MOSQ_ERR_INVAL);
pub_topic_helper("", MOSQ_ERR_INVAL);
}
@ -278,6 +280,7 @@ static void TEST_sub_topic_invalid(void)
sub_topic_helper("sub/#topic", MOSQ_ERR_INVAL);
sub_topic_helper("sub/topic#", MOSQ_ERR_INVAL);
sub_topic_helper("#/sub/topic", MOSQ_ERR_INVAL);
sub_topic_helper("", MOSQ_ERR_INVAL);
}
/* ========================================================================