From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.bugs Subject: bug#50155: don't use the conversion specifier %n in emacsclient Date: Sat, 21 Aug 2021 23:38:04 +0200 Message-ID: <87zgtaxyv7.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8741"; mail-complaints-to="usenet@ciao.gmane.io" To: 50155@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 21 23:39:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mHYhq-00023z-PA for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Aug 2021 23:39:10 +0200 Original-Received: from localhost ([::1]:49290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHYho-0007kO-RH for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Aug 2021 17:39:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYhh-0007k0-Vz for bug-gnu-emacs@gnu.org; Sat, 21 Aug 2021 17:39:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54649) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHYhh-00047X-O0 for bug-gnu-emacs@gnu.org; Sat, 21 Aug 2021 17:39:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mHYhh-0008Lt-L6 for bug-gnu-emacs@gnu.org; Sat, 21 Aug 2021 17:39:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Omar Polo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Aug 2021 21:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50155 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162958190032040 (code B ref -1); Sat, 21 Aug 2021 21:39:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Aug 2021 21:38:20 +0000 Original-Received: from localhost ([127.0.0.1]:37962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mHYh2-0008Kh-F3 for submit@debbugs.gnu.org; Sat, 21 Aug 2021 17:38:20 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:52696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mHYh0-0008KZ-Nh for submit@debbugs.gnu.org; Sat, 21 Aug 2021 17:38:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYh0-0007hz-Fn for bug-gnu-emacs@gnu.org; Sat, 21 Aug 2021 17:38:18 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:57173) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYgx-0003Zt-KP for bug-gnu-emacs@gnu.org; Sat, 21 Aug 2021 17:38:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1629581887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=duaCSGoFjVxMW6XiEVy4rTH0XRopYuHAjXtbWchNBZc=; b=rCZRLKLeoZE0ybtZxoQkbKKngBHAAalvvAlfnQRt2DQcYy9xprJehdWAjc+p89+hCMUG56 wao3DmTlgnjJI42pB6IsFvaNzzwgz7uJB4glRzgGGLUzoZwTXaZtbEuQ5FArU5iLmi+lTm k67okOzSoqxQ4NYc+tz5r8FoYxtCvUY= Original-Received: from localhost (host-79-25-237-90.retail.telecomitalia.it [79.25.237.90]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id d61752f9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Sat, 21 Aug 2021 23:38:05 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 4036a31c for ; Sat, 21 Aug 2021 23:38:04 +0200 (CEST) Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212390 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Hello, The usage of the %n conversion specifier for printf(3) is widely discouraged (see [0] for instance). The OpenBSD libc in particular logs to syslog every time an application tries to use %n. Now, in this specific case it's used in a completely safe manner, but avoiding it seems pretty easy. Another option would be char *emacsdirend = strchr(sockname + tmpdirlen + 1, '/'); but I'm not sure it would be cleaner. Thanks, Omar Polo [0]: https://man.bsd.lv/Linux-5.06/printf.3#BUGS In GNU Emacs 28.0.50 (build 11, x86_64-unknown-openbsd6.9, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2021-08-17 built on venera Windowing system distributor 'The X.Org Foundation', version 11.0.12010000 System Description: OpenBSD venera 6.9 GENERIC.MP#158 amd64 Configured using: 'configure --prefix=/home/op/opt/emacs --with-x-toolkit=lucid CC=cc' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-don-t-use-n.patch >From 18585de41f2d0dc442fe2122c25165f07913c974 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Sat, 21 Aug 2021 21:32:22 +0000 Subject: [PATCH] don't use %n --- lib-src/emacsclient.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 8346524a3e..018e81e422 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -1401,10 +1401,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen, /* Put the full address name into the buffer, since the caller might need it for diagnostics. But don't overrun the buffer. */ uintmax_t uidmax = uid; - int emacsdirlen; int suffixlen = snprintf (sockname + tmpdirlen, socknamesize - tmpdirlen, - "/emacs%"PRIuMAX"%n/%s", uidmax, &emacsdirlen, - server_name); + "/emacs%"PRIuMAX"/%s", uidmax, server_name); if (! (0 <= suffixlen && suffixlen < socknamesize - tmpdirlen)) return ENAMETOOLONG; @@ -1412,7 +1410,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen, this user's directory and does not let others write to it; this fends off some symlink attacks. To avoid races, keep the parent directory open while checking. */ - char *emacsdirend = sockname + tmpdirlen + emacsdirlen; + char *emacsdirend = sockname + tmpdirlen + suffixlen - + strlen(server_name) - 1; *emacsdirend = '\0'; int dir = openat (AT_FDCWD, sockname, O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); -- 2.32.0 --=-=-=--