From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: Re: [PATCH] Add a feature for mapping a host unix socket to a guest tcp socket
Date: Sun, 3 Aug 2025 09:09:19 +1000 [thread overview]
Message-ID: <2b270008-bdae-4f1b-bd04-e3b5cc3640e0@linaro.org> (raw)
In-Reply-To: <20250802034154.7834-1-murlockkinght@gmail.com>
On 8/2/25 13:41, Viktor Kurilko wrote:
> +#if !defined(WIN32) && SLIRP_CHECK_VERSION(4, 7, 0)
> + if (buf[0] == '/') {
> + if (is_udp) {
> + fail_reason = "Mapping unix to udp is not supported";
> + goto fail_syntax;
> + }
> + if (strlen(buf) > sizeof(host_addr.un.sun_path)) {
> + fail_reason = "Unix socket path is too long";
> + goto fail_syntax;
> + }
> + if (access(buf, F_OK) == 0) {
> + struct stat st;
> + if (stat(buf, &st) < 0) {
> + error_setg_errno(errp, errno, "Failed to stat '%s'", buf);
> + goto fail_syntax;
> + }
> +
> + if (!S_ISSOCK(st.st_mode)) {
> + fail_reason = "file exists and it's not unix socket";
> + goto fail_syntax;
> + }
> +
> + if (unlink(buf) < 0) {
> + error_setg_errno(errp, errno, "Failed to unlink '%s'", buf);
> + goto fail_syntax;
> + }
> + }
> +
> + host_addr.un.sun_family = AF_UNIX;
> + memcpy(host_addr.un.sun_path, buf, sizeof(host_addr.un.sun_path));
The memcpy length is incorrect -- buf may have strlen 2.
No need for both access and stat. If the file does not exist, stat will fail just as well
as access.
Why are you unlinking the socket?
r~
prev parent reply other threads:[~2025-08-02 23:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-02 3:41 [PATCH] Add a feature for mapping a host unix socket to a guest tcp socket Viktor Kurilko
2025-08-02 23:09 ` Richard Henderson [this message]
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=2b270008-bdae-4f1b-bd04-e3b5cc3640e0@linaro.org \
--to=richard.henderson@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).