]> git.eshelyaron.com Git - emacs.git/commitdiff
* browse-url.el (browse-url-mosaic): Be careful when writing /tmp/Mosaic.PID.
authorGlenn Morris <rgm@gnu.org>
Thu, 8 May 2014 18:10:36 +0000 (14:10 -0400)
committerGlenn Morris <rgm@gnu.org>
Thu, 8 May 2014 18:10:36 +0000 (14:10 -0400)
This is CVE-2014-3423.

Fixes: debbugs:17428
lisp/ChangeLog
lisp/net/browse-url.el

index 333bc7fcf90f80643743fd335fcb2636d8e30528..a09dd63a34fdb1ec73d9550195b38db320f0b871 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-08  Glenn Morris  <rgm@gnu.org>
+
+       * net/browse-url.el (browse-url-mosaic):
+       Be careful when writing /tmp/Mosaic.PID.  (Bug#17428)
+       This is CVE-2014-3423.
+
 2014-05-08  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * xt-mouse.el: Drop spurious/oddly shaped events (bug#17378).
index 4364490f4311aa9fafb44822159f5191addf0a4d..80dffb3fa4a8123017fb9fc9d7b9bd00460c1fb2 100644 (file)
@@ -1333,31 +1333,26 @@ used instead of `browse-url-new-window-flag'."
   (let ((pidfile (expand-file-name browse-url-mosaic-pidfile))
        pid)
     (if (file-readable-p pidfile)
-       (save-excursion
-         (find-file pidfile)
-         (goto-char (point-min))
-         (setq pid (read (current-buffer)))
-         (kill-buffer nil)))
-    (if (and pid (zerop (signal-process pid 0))) ; Mosaic running
-       (save-excursion
-         ;; This is a predictable temp-file name, which is bad,
-         ;; but it is what Mosaic uses/used.
-         ;; So it's not Emacs's problem.  http://bugs.debian.org/747100
-         (find-file (format "/tmp/Mosaic.%d" pid))
-         (erase-buffer)
-         (insert (if (browse-url-maybe-new-window new-window)
-                     "newwin\n"
-                   "goto\n")
-                 url "\n")
-         (save-buffer)
-         (kill-buffer nil)
+        (with-temp-buffer
+          (insert-file-contents pidfile)
+         (setq pid (read (current-buffer)))))
+    (if (and (integerp pid) (zerop (signal-process pid 0))) ; Mosaic running
+        (progn
+          (with-temp-buffer
+            (insert (if (browse-url-maybe-new-window new-window)
+                        "newwin\n"
+                      "goto\n")
+                    url "\n")
+            (if (file-exists-p (setq pidfile (format "/tmp/Mosaic.%d" pid)))
+                (delete-file pidfile))
+            ;; http://debbugs.gnu.org/17428.  Use O_EXCL.
+            (write-region nil nil pidfile nil 'silent nil 'excl))
          ;; Send signal SIGUSR to Mosaic
          (message "Signaling Mosaic...")
          (signal-process pid 'SIGUSR1)
          ;; Or you could try:
          ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
-         (message "Signaling Mosaic...done")
-         )
+         (message "Signaling Mosaic...done"))
       ;; Mosaic not running - start it
       (message "Starting %s..." browse-url-mosaic-program)
       (apply 'start-process "xmosaic" nil browse-url-mosaic-program