From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#35739: Bad signature from GNU ELPA Date: Wed, 15 May 2019 10:03:57 -0400 Message-ID: References: <87mujog0ao.fsf@gmail.com> <835zqca15y.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="4155"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 35739@debbugs.gnu.org, Noam Postavsky To: Richard Copley Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 15 16:05:20 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQuX1-0000qe-6S for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2019 16:05:19 +0200 Original-Received: from localhost ([127.0.0.1]:37636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQuX0-0006Ne-5S for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2019 10:05:18 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQuWn-0006Lv-LO for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 10:05:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQuWl-0001Ia-PM for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 10:05:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39568) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQuWj-0001DE-VE for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 10:05:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQuWj-0005si-Nx for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 10:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 May 2019 14:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35739 X-GNU-PR-Package: emacs Original-Received: via spool by 35739-submit@debbugs.gnu.org id=B35739.155792905122546 (code B ref 35739); Wed, 15 May 2019 14:05:01 +0000 Original-Received: (at 35739) by debbugs.gnu.org; 15 May 2019 14:04:11 +0000 Original-Received: from localhost ([127.0.0.1]:53112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQuVv-0005rZ-4g for submit@debbugs.gnu.org; Wed, 15 May 2019 10:04:11 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:12661) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQuVr-0005rM-UW for 35739@debbugs.gnu.org; Wed, 15 May 2019 10:04:09 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 816BA10087A; Wed, 15 May 2019 10:04:02 -0400 (EDT) Original-Received: from mail02.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D7AFB1006F4; Wed, 15 May 2019 10:04:00 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1557929040; bh=xNVYB+LNho+Jv4nm62ZgnWY3gd1UW1/Qxlb6k01nZFw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=BoZMgU+SeOGDqGKXUmGaiVZmKzWNMp6Dnci/KoXxiz2V37IbWeYQBQL6nrpWNzkI3 Kngm3CVKdy+TsIw0/FEdbj4iAvcIL+pGSTrEFLTJTNrgCA+A9jCbj89dDDg773plso y/kBaCkchL0PtIGix84Vdhc5aygPOxTHBH4wbNiavNNHTD4nimP4qpypCuQ8A3Qfk2 sCIhCigEkJB4lozOWPgeSV4ZlYB66Elr+OWNhSWXub4ws/7AizY1j/0Dk/a/4PJTMq xj+bDTKK2oh/c4VHbeJQpLn7TN7Ib/ApFHhP/l12FFmJU6s693kgC6Mnaa/I8LqNmK UV3g7QN2Phfhw== Original-Received: from pastel (69-196-155-191.dsl.teksavvy.com [69.196.155.191]) by mail02.iro.umontreal.ca (Postfix) with ESMTPSA id 04BC3120AA3; Wed, 15 May 2019 10:03:59 -0400 (EDT) In-Reply-To: (Richard Copley's message of "Wed, 15 May 2019 08:13:43 +0100") 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: 209.51.188.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:159341 Archived-At: > --- a/lisp/emacs-lisp/package.el > +++ b/lisp/emacs-lisp/package.el > @@ -1225,7 +1225,7 @@ package--with-work-buffer > (goto-char (point-min)) > (unless (search-forward-regexp "^\r?\n\r?" nil 'noerror) > (error "Error retrieving: %s %S" ,url-sym "incomprehensible buffer"))) > - (url-insert-buffer-contents ,b-sym ,url-sym) > + (url-insert ,b-sym) > (kill-buffer ,b-sym) > (goto-char (point-min))))) > nil [ Boy, this macro looks awfully deeply indented. We need to rewrite this to fit into the usual 80 columns. ] That actually looks very good [it would also need to change the other url-insert-file-contents in that macro, of course]. Eli, do you think this could also be a fix for bug#34909? E.g. something like the patch below? Stefan diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 949ad711ae..8a16dba1c2 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -1202,40 +1182,45 @@ package--with-work-buffer (let ((url-sym (make-symbol "url")) (b-sym (make-symbol "b-sym"))) `(cl-macrolet ((unless-error (body-2 &rest before-body) - (let ((err (make-symbol "err"))) - `(with-temp-buffer - (when (condition-case ,err - (progn ,@before-body t) - ,(list 'error ',error-form - (list 'unless ',noerror-1 - `(signal (car ,err) (cdr ,err))))) - ,@body-2))))) + (let ((err (make-symbol "err"))) + `(with-temp-buffer + (set-buffer-multibyte nil) + (when (condition-case ,err + (progn ,@before-body t) + ,(list 'error ',error-form + (list 'unless ',noerror-1 + `(signal (car ,err) + (cdr ,err))))) + ,@body-2))))) (if (string-match-p "\\`https?:" ,url-1) (let ((,url-sym (concat ,url-1 ,file))) (if ,async (unless-error nil - (url-retrieve ,url-sym - (lambda (status) - (let ((,b-sym (current-buffer))) - (require 'url-handlers) - (unless-error ,body - (when-let* ((er (plist-get status :error))) - (error "Error retrieving: %s %S" ,url-sym er)) - (with-current-buffer ,b-sym - (goto-char (point-min)) - (unless (search-forward-regexp "^\r?\n\r?" nil 'noerror) - (error "Error retrieving: %s %S" ,url-sym "incomprehensible buffer"))) - (url-insert-buffer-contents ,b-sym ,url-sym) - (kill-buffer ,b-sym) - (goto-char (point-min))))) - nil - 'silent)) - (unless-error ,body (url-insert-file-contents ,url-sym)))) + (url-retrieve + ,url-sym + (lambda (status) + (let ((,b-sym (current-buffer))) + (require 'url-handlers) + (unless-error ,body + (when-let* ((er (plist-get status :error))) + (error "Error retrieving: %s %S" ,url-sym er)) + (with-current-buffer ,b-sym + (goto-char (point-min)) + (unless (search-forward-regexp "^\r?\n\r?" nil t) + (error "Error retrieving: %s %S" + ,url-sym "incomprehensible buffer"))) + (url-insert ,b-sym) + (kill-buffer ,b-sym) + (goto-char (point-min))))) + nil + 'silent)) + (unless-error ,body (url-insert ,url-sym)))) (unless-error ,body - (let ((url (expand-file-name ,file ,url-1))) - (unless (file-name-absolute-p url) - (error "Location %s is not a url nor an absolute file name" url)) - (insert-file-contents url)))))))) + (let ((url (expand-file-name ,file ,url-1))) + (unless (file-name-absolute-p url) + (error "Location %s is not a url nor an absolute file name" + url)) + (insert-file-contents url)))))))) (define-error 'bad-signature "Failed to verify signature") @@ -1294,7 +1279,8 @@ package--check-signature (package--with-response-buffer location :file sig-file :async async :noerror t ;; Connection error is assumed to mean "no sig-file". - :error-form (let ((allow-unsigned (eq package-check-signature 'allow-unsigned))) + :error-form (let ((allow-unsigned + (eq package-check-signature 'allow-unsigned))) (when (and callback allow-unsigned) (funcall callback nil)) (when unwind (funcall unwind)) @@ -1303,8 +1289,9 @@ package--check-signature ;; OTOH, an error here means "bad signature", which we never ;; suppress. (Bug#22089) (unwind-protect - (let ((sig (package--check-signature-content (buffer-substring (point) (point-max)) - string sig-file))) + (let ((sig (package--check-signature-content + (buffer-substring (point) (point-max)) + string sig-file))) (when callback (funcall callback sig)) sig) (when unwind (funcall unwind)))))) @@ -1581,15 +1568,18 @@ package--download-one-archive (member name package-unsigned-archives)) ;; If we don't care about the signature, save the file and ;; we're done. - (progn (let ((coding-system-for-write 'utf-8)) - (write-region content nil local-file nil 'silent)) - (package--update-downloads-in-progress archive)) + (progn + (cl-assert (not enable-multibyte-characters)) + (let ((coding-system-for-write 'binary)) + (write-region content nil local-file nil 'silent)) + (package--update-downloads-in-progress archive)) ;; If we care, check it (perhaps async) and *then* write the file. (package--check-signature location file content async ;; This function will be called after signature checking. (lambda (&optional good-sigs) - (let ((coding-system-for-write 'utf-8)) + (cl-assert (not enable-multibyte-characters)) + (let ((coding-system-for-write 'binary)) (write-region content nil local-file nil 'silent)) ;; Write out good signatures into archive-contents.signed file. (when good-sigs @@ -1903,7 +1893,8 @@ package-install-from-archive ;; Update the old pkg-desc which will be shown on the description buffer. (setf (package-desc-signed pkg-desc) t) ;; Update the new (activated) pkg-desc as well. - (when-let* ((pkg-descs (cdr (assq (package-desc-name pkg-desc) package-alist)))) + (when-let* ((pkg-descs (cdr (assq (package-desc-name pkg-desc) + package-alist)))) (setf (package-desc-signed (car pkg-descs)) t)))))))))) (defun package-installed-p (package &optional min-version) @@ -2477,10 +2468,12 @@ describe-package-1 (replace-match "")))) (if (package-installed-p desc) - ;; For installed packages, get the description from the installed files. + ;; For installed packages, get the description from the + ;; installed files. (insert (package--get-description desc)) - ;; For non-built-in, non-installed packages, get description from the archive. + ;; For non-built-in, non-installed packages, get description from + ;; the archive. (let* ((basename (format "%s-readme.txt" name)) readme-string) diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index e35d999e0f..783466ca70 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el @@ -299,7 +299,8 @@ url-file-local-copy (defun url-insert (buffer &optional beg end) "Insert the body of a URL object. BUFFER should be a complete URL buffer as returned by `url-retrieve'. -If the headers specify a coding-system, it is applied to the body before it is inserted. +If the headers specify a coding-system (and current buffer is multibyte), +it is applied to the body before it is inserted. Returns a list of the form (SIZE CHARSET), where SIZE is the size in bytes of the inserted text and CHARSET is the charset that was specified in the header, or nil if none was found. @@ -311,12 +312,13 @@ url-insert (buffer-substring (+ (point-min) beg) (if end (+ (point-min) end) (point-max))) (buffer-string)))) - (charset (mail-content-type-get (mm-handle-type handle) - 'charset))) + (charset (if enable-multibyte-characters + (mail-content-type-get (mm-handle-type handle) + 'charset)))) (mm-destroy-parts handle) - (if charset - (insert (mm-decode-string data (mm-charset-to-coding-system charset))) - (insert data)) + (insert (if charset + (mm-decode-string data (mm-charset-to-coding-system charset)) + data)) (list (length data) charset))) (defvar url-http-codes)