[Slirp] [PATCH 2/6] dhcpv6: use slirp_fmt()

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Mon Jan 27 09:24:10 UTC 2020


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Warn if result is truncated, return bytes actually written (excluding \0).

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
Reviewed-by: Samuel Thibault <samuel.thibault at ens-lyon.org>
---
 src/dhcpv6.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index ce5f203..77b451b 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -179,13 +179,12 @@ static void dhcpv6_info_request(Slirp *slirp, struct sockaddr_in6 *srcsas,
         *resp++ = OPTION_BOOTFILE_URL >> 8; /* option-code high byte */
         *resp++ = OPTION_BOOTFILE_URL; /* option-code low byte */
         smaxlen = (uint8_t *)m->m_data + slirp->if_mtu - (resp + 2);
-        slen = snprintf((char *)resp + 2, smaxlen,
-                        "tftp://[%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
-                        "%02x%02x:%02x%02x:%02x%02x:%02x%02x]/%s",
-                        sa[0], sa[1], sa[2], sa[3], sa[4], sa[5], sa[6], sa[7],
-                        sa[8], sa[9], sa[10], sa[11], sa[12], sa[13], sa[14],
-                        sa[15], slirp->bootp_filename);
-        slen = MIN(slen, smaxlen);
+        slen = slirp_fmt((char *)resp + 2, smaxlen,
+                         "tftp://[%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
+                         "%02x%02x:%02x%02x:%02x%02x:%02x%02x]/%s",
+                         sa[0], sa[1], sa[2], sa[3], sa[4], sa[5], sa[6], sa[7],
+                         sa[8], sa[9], sa[10], sa[11], sa[12], sa[13], sa[14],
+                         sa[15], slirp->bootp_filename);
         *resp++ = slen >> 8; /* option-len high byte */
         *resp++ = slen; /* option-len low byte */
         resp += slen;
-- 
2.25.0.rc2.1.g09a9a1a997



More information about the Slirp mailing list