Commit 93e645e7 authored by Marc-André Lureau's avatar Marc-André Lureau
Browse files

Add mtod_check()

Recent security issues demonstrate the lack of safety care when casting
a mbuf to a particular structure type. At least, it should check that
the buffer is large enough. The following patches will make use of this
Signed-off-by: default avatarMarc-André Lureau <>
parent 5758d835
......@@ -263,3 +263,14 @@ struct mbuf *m_dup(Slirp *slirp, struct mbuf *m,
return n;
void *mtod_check(struct mbuf *m, size_t len)
if (m->m_len >= len) {
return m->m_data;
DEBUG_ERROR("mtod failed");
return NULL;
......@@ -126,6 +126,7 @@ void m_adj(struct mbuf *, int);
int m_copy(struct mbuf *, struct mbuf *, int, int);
struct mbuf *m_dup(Slirp *slirp, struct mbuf *m, bool copy_header, size_t header_size);
struct mbuf *dtom(Slirp *, void *);
void *mtod_check(struct mbuf *, size_t len);
static inline void ifs_init(struct mbuf *ifm)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment