[Slirp] [PATCH] slirp: use correct size while emulating commands

P J P ppandit at redhat.com
Wed Jan 8 12:37:54 UTC 2020


From: Prasad J Pandit <pjp at fedoraproject.org>

While emulating services in tcp_emu(), it uses 'mbuf' size
'm->m_size' to write commands via snprintf(3). Use M_ROOM(m) size
to avoid possible OOB access.

Signed-off-by: Prasad J Pandit <pjp at fedoraproject.org>
---
 src/tcp_subr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/tcp_subr.c b/src/tcp_subr.c
index b3af5b5..4b8742f 100644
--- a/src/tcp_subr.c
+++ b/src/tcp_subr.c
@@ -681,7 +681,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
             n4 = (laddr & 0xff);
 
             m->m_len = bptr - m->m_data; /* Adjust length */
-            m->m_len += snprintf(bptr, m->m_size - m->m_len,
+            m->m_len += snprintf(bptr, M_ROOM(m) - m->m_len,
                                  "ORT %d,%d,%d,%d,%d,%d\r\n%s", n1, n2, n3, n4,
                                  n5, n6, x == 7 ? buff : "");
             return 1;
@@ -717,7 +717,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
 
             m->m_len = bptr - m->m_data; /* Adjust length */
             m->m_len +=
-                snprintf(bptr, m->m_size - m->m_len,
+                snprintf(bptr, M_ROOM(m) - m->m_len,
                          "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s",
                          n1, n2, n3, n4, n5, n6, x == 7 ? buff : "");
 
@@ -744,7 +744,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
             (so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr,
                              htons(lport), SS_FACCEPTONCE)) != NULL)
             m->m_len =
-                snprintf(m->m_data, m->m_size, "%d", ntohs(so->so_fport)) + 1;
+                snprintf(m->m_data, M_ROOM(m), "%d", ntohs(so->so_fport)) + 1;
         return 1;
 
     case EMU_IRC:
-- 
2.24.1



More information about the Slirp mailing list