All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	stefanha@redhat.com, jan.kiszka@siemens.com,
	"Samuel Thibault" <samuel.thibault@ens-lyon.org>
Subject: [Qemu-devel] [PULLv3 18/32] slirp: add slirp own version of pstrcpy
Date: Tue,  5 Feb 2019 20:28:34 +0200	[thread overview]
Message-ID: <20190205182848.29887-19-samuel.thibault@ens-lyon.org> (raw)
In-Reply-To: <20190205182848.29887-1-samuel.thibault@ens-lyon.org>

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

Remove a dependency on qemu util.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 slirp/slirp.c |  4 ++--
 slirp/tftp.c  |  2 +-
 slirp/util.c  | 17 +++++++++++++++++
 slirp/util.h  |  2 ++
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/slirp/slirp.c b/slirp/slirp.c
index 9ec1e4c62f..b5c4788489 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -320,8 +320,8 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
     slirp->vprefix_len = vprefix_len;
     slirp->vhost_addr6 = vhost6;
     if (vhostname) {
-        pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
-                vhostname);
+        slirp_pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
+                      vhostname);
     }
     slirp->tftp_prefix = g_strdup(tftp_path);
     slirp->bootp_filename = g_strdup(bootfile);
diff --git a/slirp/tftp.c b/slirp/tftp.c
index 6fb381ef33..f0bcc72c92 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -216,7 +216,7 @@ static void tftp_send_error(struct tftp_session *spt,
 
   tp->tp_op = htons(TFTP_ERROR);
   tp->x.tp_error.tp_error_code = htons(errorcode);
-  pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), msg);
+  slirp_pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), msg);
 
   m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX + 2) + 3 + strlen(msg)
              - sizeof(struct udphdr);
diff --git a/slirp/util.c b/slirp/util.c
index 59f6713c8b..84f5afdbc3 100644
--- a/slirp/util.c
+++ b/slirp/util.c
@@ -188,3 +188,20 @@ int slirp_closesocket(int fd)
     return ret;
 }
 #endif /* WIN32 */
+
+void slirp_pstrcpy(char *buf, int buf_size, const char *str)
+{
+    int c;
+    char *q = buf;
+
+    if (buf_size <= 0)
+        return;
+
+    for(;;) {
+        c = *str++;
+        if (c == 0 || q >= buf + buf_size - 1)
+            break;
+        *q++ = c;
+    }
+    *q = '\0';
+}
diff --git a/slirp/util.h b/slirp/util.h
index 4f6e80c3ed..586517bb30 100644
--- a/slirp/util.h
+++ b/slirp/util.h
@@ -91,4 +91,6 @@ static inline int slirp_socket_set_fast_reuse(int fd)
 #endif
 }
 
+void slirp_pstrcpy(char *buf, int buf_size, const char *str);
+
 #endif
-- 
2.20.1

  parent reply	other threads:[~2019-02-05 18:29 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05 18:28 [Qemu-devel] [PULLv3 00/32] More work towards libslirp Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 01/32] slirp: Avoid unaligned 16bit memory access Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 02/32] slirp: Avoid marking naturally packed structs as QEMU_PACKED Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 03/32] slirp: Don't mark struct ipq or struct ipasfrag as packed Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 04/32] slirp: generalize guestfwd with a callback based approach Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 05/32] net/slirp: simplify checking for cmd: prefix Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 06/32] net/slirp: free forwarding rules on cleanup Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 07/32] net/slirp: fix leaks on forwarding rule registration error Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 08/32] slirp: add callbacks for timer Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 09/32] slirp: replace trace functions with DEBUG calls Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 10/32] slirp: replace QEMU_PACKED with SLIRP_PACKED Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 11/32] slirp: replace most qemu socket utilities with slirp own version Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 12/32] slirp: replace qemu_set_nonblock() Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 13/32] slirp: add unregister_poll_fd() callback Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 14/32] slirp: replace qemu_notify_event() with a callback Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 15/32] slirp: move QEMU state saving to a separate unit Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 16/32] slirp: do not include qemu headers in libslirp.h public API header Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 17/32] slirp: improve windows headers inclusion Samuel Thibault
2019-02-05 18:28 ` Samuel Thibault [this message]
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 19/32] slirp: remove qemu timer.h dependency Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 20/32] slirp: remove now useless QEMU headers inclusions Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 21/32] slirp: replace net/eth.h inclusion with own defines Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 22/32] slirp: replace qemu qtailq with slirp own copy Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 23/32] slirp: replace QEMU_BUILD_BUG_ON with G_STATIC_ASSERT Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 24/32] slirp: Move g_spawn_async_with_fds_qemu compatibility to slirp/ Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 25/32] slirp: replace remaining qemu headers dependency Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 26/32] slirp: prefer c99 types over BSD kind Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 27/32] slirp: improve send_packet() callback Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 28/32] slirp: replace global polling with per-instance & notifier Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 29/32] slirp: remove slirp_instances list Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 30/32] slirp: use polling callbacks, drop glib requirement Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 31/32] slirp: pass opaque to all callbacks Samuel Thibault
2019-02-05 18:28 ` [Qemu-devel] [PULLv3 32/32] slirp: API is extern C Samuel Thibault
2019-02-05 20:15 ` [Qemu-devel] [PULLv3 00/32] More work towards libslirp no-reply
2019-02-05 20:19 ` no-reply
2019-02-07 11:46 ` Peter Maydell
2019-02-07 11:53   ` Daniel P. Berrangé
2019-02-07 13:29   ` Samuel Thibault
2019-02-07 13:52     ` Marc-André Lureau
2019-02-07 13:53       ` Peter Maydell
2019-02-07 14:42     ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190205182848.29887-19-samuel.thibault@ens-lyon.org \
    --to=samuel.thibault@ens-lyon.org \
    --cc=jan.kiszka@siemens.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.