diff options
author | Prasad J Pandit <pjp@fedoraproject.org> | 2020-01-09 15:12:28 +0530 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-01-12 19:48:54 +0100 |
commit | 82ebe9c370a0e2970fb5695aa19aa5214a6a1c80 (patch) | |
tree | 4a0abfcdbe4ec6d799f740cd7cce698b2f20d7ef /src/tcp_subr.c | |
parent | ce131029d6d4a405cb7d3ac6716d03e58fb4a5d9 (diff) | |
download | slirp-82ebe9c370a0e2970fb5695aa19aa5214a6a1c80.zip slirp-82ebe9c370a0e2970fb5695aa19aa5214a6a1c80.tar.gz slirp-82ebe9c370a0e2970fb5695aa19aa5214a6a1c80.tar.bz2 |
slirp: use correct size while emulating commands
While emulating services in tcp_emu(), it uses 'mbuf' size
'm->m_size' to write commands via snprintf(3). Use M_FREEROOM(m)
size to avoid possible OOB access.
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Message-Id: <20200109094228.79764-3-ppandit@redhat.com>
Diffstat (limited to 'src/tcp_subr.c')
-rw-r--r-- | src/tcp_subr.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/tcp_subr.c b/src/tcp_subr.c index ee7a938..177dfd2 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_FREEROOM(m), "ORT %d,%d,%d,%d,%d,%d\r\n%s", n1, n2, n3, n4, n5, n6, x == 7 ? buff : ""); return 1; @@ -716,8 +716,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_FREEROOM(m), "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s", n1, n2, n3, n4, n5, n6, x == 7 ? buff : ""); @@ -743,8 +742,8 @@ int tcp_emu(struct socket *so, struct mbuf *m) if (m->m_data[m->m_len - 1] == '\0' && lport != 0 && (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; + m->m_len = snprintf(m->m_data, M_ROOM(m), + "%d", ntohs(so->so_fport)) + 1; return 1; case EMU_IRC: |