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~