From unknown Sat Jun 14 03:48:03 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#53928 <53928@debbugs.gnu.org> To: bug#53928 <53928@debbugs.gnu.org> Subject: Status: [PATCH] Allow null bytes in UNIX sockets. Reply-To: bug#53928 <53928@debbugs.gnu.org> Date: Sat, 14 Jun 2025 10:48:03 +0000 retitle 53928 [PATCH] Allow null bytes in UNIX sockets. reassign 53928 guile submitter 53928 Liliana Marie Prikler severity 53928 normal tag 53928 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Feb 10 15:49:22 2022 Received: (at submit) by debbugs.gnu.org; 10 Feb 2022 20:49:22 +0000 Received: from localhost ([127.0.0.1]:57308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nIGNV-0003Pq-SO for submit@debbugs.gnu.org; Thu, 10 Feb 2022 15:49:22 -0500 Received: from lists.gnu.org ([209.51.188.17]:57092) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nIGNT-0003Pg-8y for submit@debbugs.gnu.org; Thu, 10 Feb 2022 15:49:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIGNS-0001Jk-V1 for bug-guile@gnu.org; Thu, 10 Feb 2022 15:49:18 -0500 Received: from [2a00:1450:4864:20::542] (port=44562 helo=mail-ed1-x542.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nIGNM-0000Ue-QZ for bug-guile@gnu.org; Thu, 10 Feb 2022 15:49:18 -0500 Received: by mail-ed1-x542.google.com with SMTP id bx2so13005650edb.11 for ; Thu, 10 Feb 2022 12:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:subject:to:content-transfer-encoding:message-id :mime-version; bh=TBJLuhAA4DmxMMh7Pt0j4cFmHVCic77OQxzV65H81JA=; b=OWUO32yYiLJX2H7YpIysYCcZFC5pJQ6FJWk02isn2OU7Q5IGuNQsBYtSziojT9Ppkf mKFbimWLLf+jztzsMx3OZ9iel1kimpkM4lmnIfJWdZLQ89h5nOJWih1kyQ5B9s3xE65l hefLvYpH4+XyV/uwlyhrGuna8Adg4sv5josqkA8Uec5KmirVTcZmMZqYCnnBMvvv97PS aVQyd/nXC1lWTb8HGzoyEs0AYiDBNdz6mM3bPnEkMdkeEW6nrljTQYJihCq3xiky+6Td I7MC4L+Cloj0ge+kmbA+FzeUWIFwvgIDIjR8owOhpE97kTJqkYnovOENDnSukB/1WgHo S8pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:subject:to:content-transfer-encoding :message-id:mime-version; bh=TBJLuhAA4DmxMMh7Pt0j4cFmHVCic77OQxzV65H81JA=; b=m69NWkxyBAifKSVbgp+x5uaGKnUkbhQ0Owsk90N2nRzIcl+nwdQMgIJwg+4yJit0ZT a2FE/8NmqqAvIac4qUQEfStntljyFhtSqs6qMK0mCIbqJku2TFU8KppeW/lr0O/6DdPm jZze4dd3O8ZRNhcUniPspbV27W13bFrgmauPnb1xwZfWHjMx2sUefKpN1sXqn5apxFdZ psnrwBlDgdAZ9MS6iCg+uKsFGbyYUfnibX8lMo0ZMvenADFBhIo5yn1FDVUEXWqejEn4 fqT5vJKgiPCbnKb/eQwKw98o6+f37agrpmy6Rnw+ml7hmzmgvoc6kMO7WmwI3iyZNFmF 4OYQ== X-Gm-Message-State: AOAM533zfWIbkZh4grFjynb8eWw5R7kqwAiaBFqOKKwXKWuPZtW92Twz nju8j4+eka9cmTTSadiOeROScxZww7IhhA== X-Google-Smtp-Source: ABdhPJzFegkkh8xX31aqvGsY/AWOD81cQVz0itV0b4vgibb6+YICgyfPxdXPgbsubLiDcWzVB2hUQg== X-Received: by 2002:a05:6402:2947:: with SMTP id ed7mr10398612edb.141.1644526146721; Thu, 10 Feb 2022 12:49:06 -0800 (PST) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id o10sm4238829ejj.6.2022.02.10.12.49.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 12:49:06 -0800 (PST) From: Liliana Marie Prikler Date: Thu, 10 Feb 2022 21:42:31 +0100 Subject: [PATCH] Allow null bytes in UNIX sockets. to: bug-guile@gnu.org Content-Transfer-Encoding: 8bit Message-ID: MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::542 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::542; envelope-from=liliana.prikler@gmail.com; helo=mail-ed1-x542.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, PP_MIME_FAKE_ASCII_TEXT=0.833, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.9 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The current socket address constructors all assume, that there are no null bytes in the socket path. This assumption does not hold in Linux, which uses an initial null byte to demarcate abstract socke [...] Content analysis details: (1.9 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (liliana.prikler[at]gmail.com) -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] 0.9 PP_MIME_FAKE_ASCII_TEXT BODY: MIME text/plain claims to be ASCII but isn't -0.0 T_SCC_BODY_TEXT_LINE No description available. 1.5 SPOOFED_FREEMAIL No description available. 0.8 SPOOF_GMAIL_MID From Gmail but it doesn't seem to be... X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.5 (-) The current socket address constructors all assume, that there are no null bytes in the socket path. This assumption does not hold in Linux, which uses an initial null byte to demarcate abstract sockets and ignores all further null bytes [1]. [1] https://www.man7.org/linux/man-pages/man7/unix.7.html * libguile/sockets.c (scm_fill_sockaddr)[HAVE_UNIX_DOMAIN_SOCKETS]: Use scm_to_locale_stringn to construct c_address. Use memcpy instead of strcpy and calculate size directly instead of using SUN_LEN. (_scm_from_sockaddr): Copy the entire path up to the limits imposed by addr_size. * test-suite/tests/00-socket.test: ("make-socket-address"): Add case for abstract unix sockets. ("AF_UNIX/SOCK_STREAM"): Add abstract socket versions of bind, listen, connect and accept. --- This patch is identical to the one sent in [1]. The full thread is visible over at yhetil[2] -- one reply from May 2021 [3] isn't shown as part of it in the GNU archive. I haven't built or tested it on top of current master, but given that the patch applied cleanly, I have high hopes to say the least 🙂 [1] https://lists.gnu.org/archive/html/guile-devel/2021-03/msg00038.html [2] https://yhetil.org/guile-devel/20210329153757.16476-1-leo.priker@student.tugraz.at/ [3] https://lists.gnu.org/archive/html/guile-devel/2021-05/msg00012.html libguile/socket.c | 18 +++++--- test-suite/tests/00-socket.test | 78 +++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 10 deletions(-) diff --git a/libguile/socket.c b/libguile/socket.c index 77cdd74ef..6b77b3a14 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -813,10 +813,11 @@ scm_fill_sockaddr (int fam, SCM address, SCM *args, int which_arg, struct sockaddr_un *soka; int addr_size; char *c_address; + size_t c_address_size; scm_dynwind_begin (0); - c_address = scm_to_locale_string (address); + c_address = scm_to_locale_stringn (address, &c_address_size); scm_dynwind_free (c_address); /* the static buffer size in sockaddr_un seems to be arbitrary @@ -826,12 +827,14 @@ scm_fill_sockaddr (int fam, SCM address, SCM *args, int which_arg, connect/bind etc., to fail. sun_path is always the last member of the structure. */ addr_size = sizeof (struct sockaddr_un) - + MAX (0, strlen (c_address) + 1 - (sizeof soka->sun_path)); + + MAX (0, c_address_size + 1 - (sizeof soka->sun_path)); soka = (struct sockaddr_un *) scm_malloc (addr_size); - memset (soka, 0, addr_size); /* for sun_len: see sin_len above. */ + memset (soka, 0, addr_size); soka->sun_family = AF_UNIX; - strcpy (soka->sun_path, c_address); - *size = SUN_LEN (soka); + /* we accept 0-bytes here (used for abstract sockets in Linux); + therefore do not use strlen() or SUN_LEN! */ + memcpy (soka->sun_path, c_address, c_address_size); + *size = offsetof (struct sockaddr_un, sun_path) + c_address_size; scm_dynwind_end (); return (struct sockaddr *) soka; @@ -1045,7 +1048,10 @@ _scm_from_sockaddr (const scm_t_max_sockaddr *address, unsigned addr_size, if (addr_size <= offsetof (struct sockaddr_un, sun_path)) SCM_SIMPLE_VECTOR_SET(result, 1, SCM_BOOL_F); else - SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (nad->sun_path)); + { + size_t path_size = addr_size - offsetof (struct sockaddr_un, sun_path); + SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_stringn(nad->sun_path, path_size)); + } } break; #endif diff --git a/test-suite/tests/00-socket.test b/test-suite/tests/00-socket.test index 027bd8519..5196b4b7d 100644 --- a/test-suite/tests/00-socket.test +++ b/test-suite/tests/00-socket.test @@ -128,10 +128,15 @@ (= (sockaddr:flowinfo sa*) 1))))) (if (defined? 'AF_UNIX) - (pass-if "AF_UNIX" - (let ((sa (make-socket-address AF_UNIX "/tmp/unix-socket"))) - (and (= (sockaddr:fam sa) AF_UNIX) - (string=? (sockaddr:path sa) "/tmp/unix-socket")))))) + (begin + (pass-if "AF_UNIX" + (let ((sa (make-socket-address AF_UNIX "/tmp/unix-socket"))) + (and (= (sockaddr:fam sa) AF_UNIX) + (string=? (sockaddr:path sa) "/tmp/unix-socket")))) + (pass-if "AF_UNIX abstract" + (let ((sa (make-socket-address AF_UNIX "\x00/tmp/abstract-socket"))) + (and (= (sockaddr:fam sa) AF_UNIX) + (string=? (sockaddr:path sa) "\x00/tmp/abstract-socket"))))))) ;;; ;;; setsockopt @@ -319,6 +324,71 @@ #t) + ;; testing `bind', `listen' and `connect' on abstract stream-oriented sockets + + (let ((server-socket (socket AF_UNIX SOCK_STREAM 0)) + (server-bound? #f) + (server-listening? #f) + (server-pid #f) + (path (temp-file-path))) + + (false-if-exception (delete-file path)) + (set! path (string-append "\x00" path)) + + (pass-if "bind abstract" + (catch 'system-error + (lambda () + (bind server-socket AF_UNIX path) + (set! server-bound? #t) + #t) + (lambda args + (let ((errno (system-error-errno args))) + (cond ((= errno EADDRINUSE) (throw 'unresolved)) + (else (apply throw args))))))) + + (pass-if "listen abstract" + (if (not server-bound?) + (throw 'unresolved) + (begin + (listen server-socket 123) + (set! server-listening? #t) + #t))) + + (force-output (current-output-port)) + (force-output (current-error-port)) + (when server-listening? + (let ((pid (primitive-fork-if-available))) + ;; Spawn a server process. + (case pid + ((-1) ;; fork not available + #f) + ((0) ;; the kid: serve one connection and exit + (let serve ((conn + (false-if-exception (accept server-socket))) + (count 0)) + (if (not conn) + (exit 1) + (exit 0)))) + (else ;; the parent + (set! server-pid pid) + #t)))) + + (pass-if "connect abstract" + (if (not server-pid) + (throw 'unresolved) + (let ((s (socket AF_UNIX SOCK_STREAM 0))) + (display "connect abstract\n") + (connect s AF_UNIX path) + #t))) + + (pass-if "accept abstract" + (if (not server-pid) + (throw 'unresolved) + (begin + (let ((status (cdr (waitpid server-pid)))) + (eqv? 0 (status:exit-val status)))))) + + #t) ;; Testing `send', `recv!' & co. on stream-oriented sockets (with ;; a bit of duplication with the above.) -- 2.34.0 From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 16 04:09:24 2022 Received: (at 53928-done) by debbugs.gnu.org; 16 Jun 2022 08:09:24 +0000 Received: from localhost ([127.0.0.1]:40690 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o1kZ9-0006fc-Tf for submit@debbugs.gnu.org; Thu, 16 Jun 2022 04:09:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o1kZ8-0006fL-0n for 53928-done@debbugs.gnu.org; Thu, 16 Jun 2022 04:09:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55158) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1kZ2-0006GJ-PN; Thu, 16 Jun 2022 04:09:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=g82pTAC1HGLj0wWRuAEBLC0gCp/BpzOdgE+Uzh28A7A=; b=cWFLl/9cB0a4BolWGPc5 jgM3vPYTy5WEUAaNUBALB47m6EN3Fe5Edy8F/YrYswxJEY61bJoDso4t0ftnk9cPkV1wUXzhvLcq4 UsHzSBHmNb8aq+O0/9g+EytlmqXUWk2yyyf4ZeOjgJVMHejsvHKhIEPt9QeClIbdYL7NEMil/N2lf WXSQhYhK7/hQEhhlIthN3iYy2HU/ISFFnuMM1kAfZANGGv5cMiF3GKrX65RKT1o/Fifoe9Akw+8zy +ylLWgWcZfgyj/t7/OyGVXjc2oRJyrbhN7yUAYugJjMSyotl+IMIfrAAsghDJsnLdjihXpwNeN0CX JInePvXnOJw8vQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:49667 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1kZ0-0000UY-Uf; Thu, 16 Jun 2022 04:09:16 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Liliana Marie Prikler Subject: Re: bug#53928: [PATCH] Allow null bytes in UNIX sockets. References: Date: Thu, 16 Jun 2022 10:09:13 +0200 In-Reply-To: (Liliana Marie Prikler's message of "Thu, 10 Feb 2022 21:42:31 +0100") Message-ID: <87r13pni6u.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 53928-done Cc: 53928-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Liliana Marie Prikler skribis: > The current socket address constructors all assume, that there are no > null bytes in the socket path. This assumption does not hold in Linux, > which uses an initial null byte to demarcate abstract sockets and > ignores all further null bytes [1]. > > [1] https://www.man7.org/linux/man-pages/man7/unix.7.html > > * libguile/sockets.c (scm_fill_sockaddr)[HAVE_UNIX_DOMAIN_SOCKETS]: > Use scm_to_locale_stringn to construct c_address. > Use memcpy instead of strcpy and calculate size directly instead of > using SUN_LEN. > (_scm_from_sockaddr): Copy the entire path up to the limits imposed by > addr_size. > * test-suite/tests/00-socket.test: ("make-socket-address"): Add case for > abstract unix sockets. > ("AF_UNIX/SOCK_STREAM"): Add abstract socket versions of bind, listen, > connect and accept. Finally applied, thanks! Ludo=E2=80=99. From unknown Sat Jun 14 03:48:03 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 14 Jul 2022 11:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator