Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
332bcb39
Commit
332bcb39
authored
Apr 19, 2017
by
Nathaniel Wesley Filardo
Committed by
Arnim Läuger
Apr 19, 2017
Browse files
mqtt: fix several buffer length checks (#1906)
Partially addresses nodemcu/nodemcu-firmware#1773.
parent
d777fdc5
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/mqtt/mqtt_msg.c
View file @
332bcb39
...
...
@@ -162,7 +162,7 @@ const char* mqtt_get_publish_topic(uint8_t* buffer, uint16_t* length)
}
totlen
+=
i
;
if
(
i
+
2
>
=
*
length
)
if
(
i
+
2
>
*
length
)
return
NULL
;
topiclen
=
buffer
[
i
++
]
<<
8
;
topiclen
|=
buffer
[
i
++
];
...
...
@@ -191,12 +191,12 @@ const char* mqtt_get_publish_data(uint8_t* buffer, uint16_t* length)
}
totlen
+=
i
;
if
(
i
+
2
>
=
*
length
)
if
(
i
+
2
>
*
length
)
return
NULL
;
topiclen
=
buffer
[
i
++
]
<<
8
;
topiclen
|=
buffer
[
i
++
];
if
(
i
+
topiclen
>
=
*
length
){
if
(
i
+
topiclen
>
*
length
){
*
length
=
0
;
return
NULL
;
}
...
...
@@ -204,7 +204,7 @@ const char* mqtt_get_publish_data(uint8_t* buffer, uint16_t* length)
if
(
mqtt_get_qos
(
buffer
)
>
0
)
{
if
(
i
+
2
>
=
*
length
)
if
(
i
+
2
>
*
length
)
return
NULL
;
i
+=
2
;
}
...
...
@@ -231,6 +231,9 @@ uint16_t mqtt_get_id(uint8_t* buffer, uint16_t length)
int
i
;
int
topiclen
;
if
(
mqtt_get_qos
(
buffer
)
<=
0
)
return
0
;
for
(
i
=
1
;
i
<
length
;
++
i
)
{
if
((
buffer
[
i
]
&
0x80
)
==
0
)
...
...
@@ -240,23 +243,17 @@ uint16_t mqtt_get_id(uint8_t* buffer, uint16_t length)
}
}
if
(
i
+
2
>
=
length
)
if
(
i
+
2
>
length
)
return
0
;
topiclen
=
buffer
[
i
++
]
<<
8
;
topiclen
|=
buffer
[
i
++
];
if
(
i
+
topiclen
>
=
length
)
if
(
i
+
topiclen
>
length
)
return
0
;
i
+=
topiclen
;
if
(
mqtt_get_qos
(
buffer
)
>
0
)
{
if
(
i
+
2
>=
length
)
return
0
;
//i += 2;
}
else
{
return
0
;
}
if
(
i
+
2
>
length
)
return
0
;
return
(
buffer
[
i
]
<<
8
)
|
buffer
[
i
+
1
];
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment