mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
assorted patches
This commit is contained in:
1 parent
07a49a7a2d
commit
a9df523f76
34 files changed
+1240
-592
No files matched your search
+21
-17
@@ -198,12 +198,15 @@ static bool mg_send_mqtt_properties(struct mg_connection *c,
|
||||
|
||||
size_t mg_mqtt_next_prop(struct mg_mqtt_message *msg, struct mg_mqtt_prop *prop,
|
||||
size_t ofs) {
|
||||
uint8_t *i = (uint8_t *) msg->dgram.buf + msg->props_start + ofs;
|
||||
uint8_t *end = (uint8_t *) msg->dgram.buf + msg->dgram.len;
|
||||
uint8_t *props = (uint8_t *) msg->dgram.buf + msg->props_start;
|
||||
uint8_t *props_end = props + msg->props_size;
|
||||
uint8_t *i = props + ofs;
|
||||
size_t new_pos = ofs, len;
|
||||
|
||||
if (ofs >= msg->dgram.len || ofs >= msg->props_start + msg->props_size || (i + 1) >= end)
|
||||
return 0;
|
||||
|
||||
if (msg->props_start > msg->dgram.len ||
|
||||
msg->props_size > msg->dgram.len - msg->props_start ||
|
||||
ofs >= msg->props_size)
|
||||
return 0;
|
||||
|
||||
memset(prop, 0, sizeof(struct mg_mqtt_prop));
|
||||
prop->id = i[0];
|
||||
@@ -211,49 +214,50 @@ size_t mg_mqtt_next_prop(struct mg_mqtt_message *msg, struct mg_mqtt_prop *prop,
|
||||
|
||||
switch (mqtt_prop_type_by_id(prop->id)) {
|
||||
case MQTT_PROP_TYPE_STRING_PAIR:
|
||||
if (i + 2 >= end) return 0;
|
||||
if (i + 2 > props_end) return 0;
|
||||
prop->key.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
|
||||
if (i + 2 + prop->key.len > props_end) return 0;
|
||||
prop->key.buf = (char *) i + 2;
|
||||
i += 2 + prop->key.len;
|
||||
if (i + 2 >= end) return 0;
|
||||
if (i + 2 > props_end) return 0;
|
||||
prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
|
||||
prop->val.buf = (char *) i + 2;
|
||||
if (i + 2 + prop->val.len >= end) return 0;
|
||||
if (i + 2 + prop->val.len > props_end) return 0;
|
||||
new_pos += 2 * sizeof(uint16_t) + prop->val.len + prop->key.len;
|
||||
break;
|
||||
case MQTT_PROP_TYPE_BYTE:
|
||||
if (i + 1 >= end) return 0;
|
||||
if (i + 1 > props_end) return 0;
|
||||
prop->iv = (uint8_t) i[0];
|
||||
new_pos++;
|
||||
break;
|
||||
case MQTT_PROP_TYPE_SHORT:
|
||||
if (i + 2 >= end) return 0;
|
||||
if (i + 2 > props_end) return 0;
|
||||
prop->iv = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
|
||||
new_pos += sizeof(uint16_t);
|
||||
break;
|
||||
case MQTT_PROP_TYPE_INT:
|
||||
if (i + 4 >= end) return 0;
|
||||
if (i + 4 > props_end) return 0;
|
||||
prop->iv = ((uint32_t) i[0] << 24) | ((uint32_t) i[1] << 16) |
|
||||
((uint32_t) i[2] << 8) | i[3];
|
||||
new_pos += sizeof(uint32_t);
|
||||
break;
|
||||
case MQTT_PROP_TYPE_STRING:
|
||||
if (i + 2 >= end) return 0;
|
||||
if (i + 2 > props_end) return 0;
|
||||
prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
|
||||
prop->val.buf = (char *) i + 2;
|
||||
if (i + 2 + prop->val.len >= end) return 0;
|
||||
if (i + 2 + prop->val.len > props_end) return 0;
|
||||
new_pos += 2 + prop->val.len;
|
||||
break;
|
||||
case MQTT_PROP_TYPE_BINARY_DATA:
|
||||
if (i + 2 >= end) return 0;
|
||||
if (i + 2 > props_end) return 0;
|
||||
prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
|
||||
prop->val.buf = (char *) i + 2;
|
||||
if (i + 2 + prop->val.len >= end) return 0;
|
||||
if (i + 2 + prop->val.len > props_end) return 0;
|
||||
new_pos += 2 + prop->val.len;
|
||||
break;
|
||||
case MQTT_PROP_TYPE_VARIABLE_INT:
|
||||
len = decode_varint(i, (size_t) (end - i), &prop->iv);
|
||||
if (i + len >= end) return 0;
|
||||
len = decode_varint(i, (size_t) (props_end - i), &prop->iv);
|
||||
if (i + len > props_end) return 0;
|
||||
new_pos = (len == 0) ? 0 : new_pos + len;
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user