tftp: check tftp_input buffer size
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 4 Jun 2021 12:34:30 +0000 (16:34 +0400)
committerwanchao-xu <wanchao.xu@samsung.com>
Tue, 9 Jan 2024 12:03:44 +0000 (20:03 +0800)
Git-commmit: 3f17948137155f025f7809fdc38576d5d2451c3d
References: bsc#1187366, CVE-2021-3595

Fixes: CVE-2021-3595
Fixes: https://gitlab.freedesktop.org/slirp/libslirp/-/issues/46
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Jose R Ziviani <jose.ziviani@suse.com>
slirp/src/tftp.c

index c209145282fac8afdf57dc17bcf5afa6f7a17edd..5a6279396684ef809742bbbd0ee3fceb0fdfb2a0 100644 (file)
@@ -444,7 +444,11 @@ static void tftp_handle_error(Slirp *slirp, struct sockaddr_storage *srcsas,
 
 void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m)
 {
-    struct tftp_t *tp = (struct tftp_t *)m->m_data;
+    struct tftp_t *tp = mtod_check(m, offsetof(struct tftp_t, x.tp_buf));
+
+    if (tp == NULL) {
+        return;
+    }
 
     switch (ntohs(tp->tp_op)) {
     case TFTP_RRQ: