From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#30005: 27.0.50; call-interactively doesn't work correctly if the interactive specification has an embedded null byte Date: Sat, 20 Jan 2018 14:02:42 +0200 Message-ID: <83y3ksspp9.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1516449749 5922 195.159.176.226 (20 Jan 2018 12:02:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 20 Jan 2018 12:02:29 +0000 (UTC) Cc: 30005@debbugs.gnu.org To: Philipp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 20 13:02:24 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecrqc-0000UV-Hu for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Jan 2018 13:02:11 +0100 Original-Received: from localhost ([::1]:34665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecrsc-0001iP-Hh for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Jan 2018 07:04:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecrsV-0001hV-7G for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 07:04:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecrsQ-0005Rt-9r for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 07:04:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55948) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ecrsQ-0005Rk-5O for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 07:04:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ecrsP-0007LN-NZ for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 07:04:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Jan 2018 12:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30005 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30005-submit@debbugs.gnu.org id=B30005.151644979228171 (code B ref 30005); Sat, 20 Jan 2018 12:04:01 +0000 Original-Received: (at 30005) by debbugs.gnu.org; 20 Jan 2018 12:03:12 +0000 Original-Received: from localhost ([127.0.0.1]:35612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecrrc-0007KJ-7O for submit@debbugs.gnu.org; Sat, 20 Jan 2018 07:03:12 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:49928) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecrrZ-0007K5-PO for 30005@debbugs.gnu.org; Sat, 20 Jan 2018 07:03:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecrrR-0004Tf-HK for 30005@debbugs.gnu.org; Sat, 20 Jan 2018 07:03:04 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecrrR-0004TZ-B9; Sat, 20 Jan 2018 07:03:01 -0500 Original-Received: from [176.228.60.248] (port=3677 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ecrrQ-00049m-N8; Sat, 20 Jan 2018 07:03:01 -0500 In-reply-to: (message from Philipp on Sat, 06 Jan 2018 12:39:43 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:142318 Archived-At: > From: Philipp > Date: Sat, 06 Jan 2018 12:39:43 +0100 > > (call-interactively (lambda (a b) (interactive "sa\0b\ns"))) > > the prompt is only "a" and a `wrong-number-of-argument' signal is > raised. This is because `call-interactively' copies the interactive > specification to a C string, ignoring embedded nulls. No, it copies the spec in its entirety, including embedded null bytes, but then _processes_ the result as a C string, taking the first null byte as the end of the string. Does the patch below look right, and give good results? diff --git a/src/callint.c b/src/callint.c index 2253cdf..3d2ed00 100644 --- a/src/callint.c +++ b/src/callint.c @@ -288,7 +288,8 @@ invoke it. If KEYS is omitted or nil, the return value of ptrdiff_t next_event; Lisp_Object prefix_arg; - char *string; + char *string, *string_end; + ptrdiff_t string_len; const char *tem; /* If varies[i] > 0, the i'th argument shouldn't just have its value @@ -396,6 +397,8 @@ invoke it. If KEYS is omitted or nil, the return value of /* SPECS is set to a string; use it as an interactive prompt. Copy it so that STRING will be valid even if a GC relocates SPECS. */ SAFE_ALLOCA_STRING (string, specs); + string_len = SBYTES (specs); + string_end = string + string_len; /* Here if function specifies a string to control parsing the defaults. */ @@ -418,7 +421,7 @@ invoke it. If KEYS is omitted or nil, the return value of if (!NILP (record_flag)) { char *p = string; - while (*p) + while (p < string_end) { if (! (*p == 'r' || *p == 'p' || *p == 'P' || *p == '\n')) @@ -469,7 +472,7 @@ invoke it. If KEYS is omitted or nil, the return value of `funcall-interactively') plus the number of arguments the interactive spec would have us give to the function. */ tem = string; - for (nargs = 2; *tem; ) + for (nargs = 2; tem < string_end; ) { /* 'r' specifications ("point and mark as 2 numeric args") produce *two* arguments. */ @@ -477,7 +480,7 @@ invoke it. If KEYS is omitted or nil, the return value of nargs += 2; else nargs++; - tem = strchr (tem, '\n'); + tem = memchr (tem, '\n', string_len - (tem - string)); if (tem) ++tem; else @@ -503,9 +506,12 @@ invoke it. If KEYS is omitted or nil, the return value of specbind (Qenable_recursive_minibuffers, Qt); tem = string; - for (i = 2; *tem; i++) + for (i = 2; tem < string_end; i++) { - visargs[1] = make_string (tem + 1, strcspn (tem + 1, "\n")); + char *pnl = memchr (tem + 1, '\n', string_len - (tem + 1 - string)); + ptrdiff_t sz = pnl ? pnl - (tem + 1) : string_end - (tem + 1); + + visargs[1] = make_string (tem + 1, sz); callint_message = Fformat_message (i - 1, visargs + 1); switch (*tem) @@ -781,7 +787,7 @@ invoke it. If KEYS is omitted or nil, the return value of { /* How many bytes are left unprocessed in the specs string? (Note that this excludes the trailing null byte.) */ - ptrdiff_t bytes_left = SBYTES (specs) - (tem - string); + ptrdiff_t bytes_left = string_len - (tem - string); unsigned letter; /* If we have enough bytes left to treat the sequence as a @@ -803,9 +809,9 @@ invoke it. If KEYS is omitted or nil, the return value of if (NILP (visargs[i]) && STRINGP (args[i])) visargs[i] = args[i]; - tem = strchr (tem, '\n'); + tem = memchr (tem, '\n', string_len - (tem - string)); if (tem) tem++; - else tem = ""; + else tem = string_end; } unbind_to (speccount, Qnil);