mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 23:18:52 +00:00
sdp: prevent the sdp message parser from reading past the end of the buffer
Otherwise, a malformed SDP message could crash the application, or even maliciously gather data from the memory located after this buffer... https://bugzilla.gnome.org/show_bug.cgi?id=750096
This commit is contained in:
parent
a998d380bd
commit
6ab46d8f0a
1 changed files with 23 additions and 3 deletions
|
@ -2962,21 +2962,33 @@ gst_sdp_message_parse_buffer (const guint8 * data, guint size,
|
||||||
c.msg = msg;
|
c.msg = msg;
|
||||||
c.media = NULL;
|
c.media = NULL;
|
||||||
|
|
||||||
|
#define SIZE_CHECK_GUARD \
|
||||||
|
G_STMT_START { \
|
||||||
|
if (p - (gchar *) data >= size) \
|
||||||
|
goto out; \
|
||||||
|
} G_STMT_END
|
||||||
|
|
||||||
p = (gchar *) data;
|
p = (gchar *) data;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
while (g_ascii_isspace (*p))
|
while (p - (gchar *) data < size && g_ascii_isspace (*p))
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
|
SIZE_CHECK_GUARD;
|
||||||
|
|
||||||
type = *p++;
|
type = *p++;
|
||||||
if (type == '\0')
|
if (type == '\0')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
SIZE_CHECK_GUARD;
|
||||||
|
|
||||||
if (*p != '=')
|
if (*p != '=')
|
||||||
goto line_done;
|
goto line_done;
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
|
SIZE_CHECK_GUARD;
|
||||||
|
|
||||||
s = p;
|
s = p;
|
||||||
while (*p != '\n' && *p != '\r' && *p != '\0')
|
while (p - (gchar *) data < size && *p != '\n' && *p != '\r' && *p != '\0')
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
len = p - s;
|
len = p - s;
|
||||||
|
@ -2989,13 +3001,21 @@ gst_sdp_message_parse_buffer (const guint8 * data, guint size,
|
||||||
|
|
||||||
gst_sdp_parse_line (&c, type, buffer);
|
gst_sdp_parse_line (&c, type, buffer);
|
||||||
|
|
||||||
|
SIZE_CHECK_GUARD;
|
||||||
|
|
||||||
line_done:
|
line_done:
|
||||||
while (*p != '\n' && *p != '\0')
|
while (p - (gchar *) data < size && *p != '\n' && *p != '\0')
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
|
SIZE_CHECK_GUARD;
|
||||||
|
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef SIZE_CHECK_GUARD
|
||||||
|
|
||||||
|
out:
|
||||||
if (buffer)
|
if (buffer)
|
||||||
g_free (buffer);
|
g_free (buffer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue