From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "" Newsgroups: gmane.emacs.bugs Subject: bug#15866: Gnutls elisp code doesn't properly check for file existence Date: Mon, 11 Nov 2013 19:20:08 -0500 Message-ID: <21121.29752.814965.329395@consult.pretender> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1384215746 14130 80.91.229.3 (12 Nov 2013 00:22:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 12 Nov 2013 00:22:26 +0000 (UTC) To: 15866@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 12 01:22:26 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vg1kO-0003CG-Rd for geb-bug-gnu-emacs@m.gmane.org; Tue, 12 Nov 2013 01:22:25 +0100 Original-Received: from localhost ([::1]:40184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg1kO-0001TC-0R for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Nov 2013 19:22:24 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg1kC-0001SA-3d for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:22:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vg1k2-0005Tl-In for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:22:12 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33563) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg1k2-0005Th-F5 for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:22:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Vg1k2-0006iH-0b for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Nov 2013 00:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 15866 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.138421566525737 (code B ref -1); Tue, 12 Nov 2013 00:22:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Nov 2013 00:21:05 +0000 Original-Received: from localhost ([127.0.0.1]:47582 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vg1j6-0006h2-8b for submit@debbugs.gnu.org; Mon, 11 Nov 2013 19:21:05 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:33538) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vg1j4-0006gU-3D for submit@debbugs.gnu.org; Mon, 11 Nov 2013 19:21:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vg1ip-0005BD-6R for submit@debbugs.gnu.org; Mon, 11 Nov 2013 19:20:56 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:57295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg1ip-0005B9-3G for submit@debbugs.gnu.org; Mon, 11 Nov 2013 19:20:47 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg1ih-0001Mz-Lg for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:20:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vg1ia-00058z-5q for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:20:39 -0500 Original-Received: from vms173015pub.verizon.net ([206.46.173.15]:53862) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg1iZ-00058l-Tu for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 19:20:32 -0500 Original-Received: from consult.pretender ([unknown] [72.93.211.153]) by vms173015.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0MW400H2SJLLP860@vms173015.mailsrvcs.net> for bug-gnu-emacs@gnu.org; Mon, 11 Nov 2013 18:20:10 -0600 (CST) Original-Received: from consult.pretender (consult.pretender [127.0.0.1]) by consult.pretender (8.14.4/8.14.4) with ESMTP id rAC0K8T3025141 for ; Mon, 11 Nov 2013 19:20:09 -0500 X-Mailer: VM 8.2.0b under 23.1.1 (i386-redhat-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:80290 Archived-At: The function gnutls-negotiate uses the (potentially) magic-file-enabled predicate file-exists-p to check for the "existence" of files in the gnutls-trustfiles list before passing the raw file paths on as-is to the gnutls c-code. The elements of the problem are as follows 1. The predicate file-exists-p potentially references magic-file-handler(s) so that we really are only testing for the existence of the magic-modified file path. At the same time the c-code is unaware of magic-file-handlers and assumes the raw path is a standard OS-accessible path without any magic modification. In particular, I have encountered this inconsistency with the cygwin-mount magic file handler, but the same problem will occur with *any* magic file handler that causes a non-OS recognizable path to test as existing with file-exists-p. 2. When the gnutls c-code is passed a file path that the OS can't find, it crashes the gnutls calling function without any human-readable or understandable error message. The error code passed back is "-64" whic presumably must mean something like "file not found" 3. Gnutls.el implicitly supports cygwin since a cygwin-style trustfile is included in gnutls-trustfiles and labeled as such. This presumably works fine in a cygwin-compiled version of emacs but if one uses a generic windows-native version of Emacs with cygwin-mount as the magic file handler then problems (1) & (2) cause gnutls to crash every time. Luckily, there is a near trivial patch that does the following: i] If the function 'expand-file-name' has an associated magic file handler, the function expand-file-name is called to convert it "to absolute, and canonicalize it" (quoted from the function definition). ii] The test for file-exists-p is then wrapped in a 'let' construct with file-name-handler-alist set to nil. This effectively shuts off magic file handling and ensures that file-exists-p now checks for true OS existence of the now potentially expanded path. iii]The function gnutls-trustfiles is now assured that it will be passed an OS-valid path. --- gnutls.el 2013-03-17 13:52:40.000000000 -0400 +++ gnutls.el.new 2013-10-23 12:47:36.503554500 -0400 @@ -174,7 +174,8 @@ (let* ((type (or type 'gnutls-x509pki)) (trustfiles (or trustfiles (delq nil - (mapcar (lambda (f) (and f (file-exists-p f) f)) + (mapcar (lambda (f) + (and f + (if (find-file-name-handler f 'expand-file-name) + (setq f (expand-file-name f))) + (let (file-name-handler-alist) + (file-exists-p f)) f)) (if (functionp gnutls-trustfiles) (funcall gnutls-trustfiles) gnutls-trustfiles))))) The patch could of course be extended to 'catch' any error and display an error message like "Error: gntuls trustfile xxxxx not found" rather than crashing if somehow there is still a file access issue. I generate the error using the following: (require 'cygwin-mount) (require 'gnutls) (open-gnutls-stream "tls" "tls-buffer" "imap.gmail.com" "imaps") The emacs debugger, gives the following results: Debugger entered--Lisp error: (gnutls-error # -64) signal(gnutls-error (# -64)) gnutls-negotiate(:process # :type gnutls-x509pki :hostname "imap.gmail.com") open-gnutls-stream("tls" "tls-buffer" "imap.gmail.com" "imaps") eval-region(19 83 t #[257 "\300\242b\210\301\207" [(83) (open-gnutls-stream "tls" "tls-buffer" "imap.gmail.com" "imaps")] 2 "\n\n(fn IGNORE)"]) ; Reading at buffer position 83 eval-defun-2() eval-defun(nil) call-interactively(eval-defun nil nil) command-execute(eval-defun) -------------------------------------------------------------------------- In GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601) of 2013-03-17 on MARVIN Windowing system distributor `Microsoft Corp.', version 6.1.7601 Configured using: `configure --with-gcc (4.7) --cflags -ID:/devel/emacs/libs/libXpm-3.5.8/include -ID:/devel/emacs/libs/libXpm-3.5.8/src -ID:/devel/emacs/libs/libpng-dev_1.4.3-1/include -ID:/devel/emacs/libs/zlib-dev_1.2.5-2/include -ID:/devel/emacs/libs/giflib-4.1.4-1/include -ID:/devel/emacs/libs/jpeg-6b-4/include -ID:/devel/emacs/libs/tiff-3.8.2-1/include -ID:/devel/emacs/libs/gnutls-3.0.9/include -ID:/devel/emacs/libs/libiconv-1.13.1-1-dev/include -ID:/devel/emacs/libs/libxml2-2.7.8/include/libxml2' Important settings: value of $LANG: ENU locale-coding-system: cp1252 default enable-multibyte-characters: t Major mode: Text Minor modes in effect: shell-dirtrack-mode: t display-time-mode: t tooltip-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t auto-fill-function: do-auto-fill transient-mark-mode: t abbrev-mode: t Recent input: r Recent messages: Quit Deleting...done (No files need saving) Marking holidays...done Marking holidays...done Undo! Mark saved where search started [2 times] Making completion list... [3 times] delete-backward-char: Text is read-only [2 times] Making completion list... Load-path shadows: None found. Features: (shadow sort emacsbug echistory chistory solar cal-dst cal-julian cal-hebrew holidays hol-loaddefs cal-move cal-tex jjk-calendar cal-menu calendar cal-loaddefs dired-aux browse-url url-util url-parse url-vars ruler-mode hl-line hexl eldoc mule-util tramp-cmds noutline outline easy-mmode tramp-cache tramp-sh tramp tramp-compat tramp-loaddefs shell pcomplete find-func ebuff-menu pp misearch multi-isearch nxml-uchnm rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc xmltok network-stream starttls tls message idna format-spec mml mml-sec mm-decode mm-bodies mm-encode gmm-utils mailheader vm-imap bbdb-gui help-mode flyspell ispell cl-macs gv vm-reply easymenu jjk-vm dired vm-mime-display-internal-application vm-ps-print bbdb-vm vm-autoload bbdb-snarf mail-extr rfc822 bbdb-autoloads bbdb-hooks mail-parse rfc2231 bbdb-com mailabbrev cl vcard vm-vcard vm-pine smtpmail bbdb timezone sendmail rfc2047 rfc2045 ietf-drums mail-utils vm-rfaddons vm-menu vm-window vm-toolbar vm-folder vm-mime vm-undo vm-virtual vm-summary-faces vm-summary vm-mouse vm-page vm-motion vm-minibuf vm-message vm-misc vm-macro vm-autoloads vm-vars vm-version vm jjk-comments jjk-load ps-print ps-def lpr jjk-print ibm-keymaps jjk-frames jjk-hooks jjk-keymaps ehelp electric uniquify warnings arc-mode archive-mode jjk-lib epa-file epa derived epg epg-config advice help-fns cl-lib advice-preload auth-source eieio byte-opt bytecomp byte-compile cconv gnus-util mm-util mail-prsvr password-cache cygwin-mount ange-ftp comint ansi-color ring server time time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp w32-common-fns disp-table w32-win w32-vars tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process w32 multi-tty emacs) In GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601) of 2013-03-17 on MARVIN Windowing system distributor `Microsoft Corp.', version 6.1.7601 Configured using: `configure --with-gcc (4.7) --cflags -ID:/devel/emacs/libs/libXpm-3.5.8/include -ID:/devel/emacs/libs/libXpm-3.5.8/src -ID:/devel/emacs/libs/libpng-dev_1.4.3-1/include -ID:/devel/emacs/libs/zlib-dev_1.2.5-2/include -ID:/devel/emacs/libs/giflib-4.1.4-1/include -ID:/devel/emacs/libs/jpeg-6b-4/include -ID:/devel/emacs/libs/tiff-3.8.2-1/include -ID:/devel/emacs/libs/gnutls-3.0.9/include -ID:/devel/emacs/libs/libiconv-1.13.1-1-dev/include -ID:/devel/emacs/libs/libxml2-2.7.8/include/libxml2' Important settings: value of $LANG: ENU locale-coding-system: cp1252 default enable-multibyte-characters: t Major mode: Text Minor modes in effect: shell-dirtrack-mode: t display-time-mode: t tooltip-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t auto-fill-function: do-auto-fill transient-mark-mode: t abbrev-mode: t Recent input: r Recent messages: Quit Deleting...done Undo! Mark saved where search started [2 times] Making completion list... [3 times] delete-backward-char: Text is read-only [2 times] Making completion list... Load-path shadows: None found. Features: (shadow sort emacsbug echistory chistory solar cal-dst cal-julian cal-hebrew holidays hol-loaddefs cal-move cal-tex jjk-calendar cal-menu calendar cal-loaddefs dired-aux browse-url url-util url-parse url-vars ruler-mode hl-line hexl eldoc mule-util tramp-cmds noutline outline easy-mmode tramp-cache tramp-sh tramp tramp-compat tramp-loaddefs shell pcomplete find-func ebuff-menu pp misearch multi-isearch nxml-uchnm rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc xmltok network-stream starttls tls message idna format-spec mml mml-sec mm-decode mm-bodies mm-encode gmm-utils mailheader vm-imap bbdb-gui help-mode flyspell ispell cl-macs gv vm-reply easymenu jjk-vm dired vm-mime-display-internal-application vm-ps-print bbdb-vm vm-autoload bbdb-snarf mail-extr rfc822 bbdb-autoloads bbdb-hooks mail-parse rfc2231 bbdb-com mailabbrev cl vcard vm-vcard vm-pine smtpmail bbdb timezone sendmail rfc2047 rfc2045 ietf-drums mail-utils vm-rfaddons vm-menu vm-window vm-toolbar vm-folder vm-mime vm-undo vm-virtual vm-summary-faces vm-summary vm-mouse vm-page vm-motion vm-minibuf vm-message vm-misc vm-macro vm-autoloads vm-vars vm-version vm ehelp electric uniquify warnings arc-mode archive-mode epa-file epa derived epg epg-config advice help-fns cl-lib advice-preload auth-source eieio byte-opt bytecomp byte-compile cconv gnus-util mm-util mail-prsvr password-cache cygwin-mount ange-ftp comint ansi-color ring server time time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp w32-common-fns disp-table w32-win w32-vars tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process w32 multi-tty emacs)