diff options
| author | Paul Eggert | 2018-08-21 13:44:03 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-21 13:44:32 -0700 |
| commit | f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd (patch) | |
| tree | 5f42e48e12a0ec77bd5cd5f32255a534635e89bf /lisp/net | |
| parent | 81e7eef8224c8a99a207b7a7b9dae1d598392ef7 (diff) | |
| download | emacs-f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd.tar.gz emacs-f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd.zip | |
Audit use of lsh and fix glitches
I audited use of lsh in the Lisp source code, and fixed the
glitches that I found. While I was at it, I replaced uses of lsh
with ash when either will do. Replacement is OK when either
argument is known to be nonnegative, or when only the low-order
bits of the result matter, and is a (minor) win since ash is a bit
more solid than lsh nowadays, and is a bit faster.
* lisp/calc/calc-ext.el (math-check-fixnum):
Prefer most-positive-fixnum to (lsh -1 -1).
* lisp/vc/vc-hg.el (vc-hg-state-fast): When testing fixnum width,
prefer (zerop (ash most-positive-fixnum -32)) to (zerop (lsh -1
32)) (Bug#32485#11).
* lisp/emacs-lisp/bytecomp.el (byte-compile-lapcode):
Tighten sanity-check for bytecode overflow, by checking that the
result of (ash pc -8) is nonnegative. Formerly this check was not
needed since lsh was used and the number overflowed differently.
* lisp/net/dns.el (dns-write): Fix some obvious sign typos in
shift counts. Evidently this part of the code has never been
exercised.
* lisp/progmodes/hideif.el (hif-shiftleft, hif-shiftright):
* lisp/term/common-win.el (x-setup-function-keys):
Simplify.
* admin/unidata/unidata-gen.el, admin/unidata/uvs.el:
* doc/lispref/keymaps.texi, doc/lispref/syntax.texi:
* doc/misc/calc.texi, doc/misc/cl.texi, etc/NEWS.19:
* lisp/arc-mode.el, lisp/calc/calc-bin.el, lisp/calc/calc-comb.el:
* lisp/calc/calc-ext.el, lisp/calc/calc-math.el:
* lisp/cedet/semantic/wisent/comp.el, lisp/composite.el:
* lisp/disp-table.el, lisp/dos-fns.el, lisp/edmacro.el:
* lisp/emacs-lisp/bindat.el, lisp/emacs-lisp/byte-opt.el:
* lisp/emacs-lisp/bytecomp.el, lisp/emacs-lisp/cl-extra.el:
* lisp/erc/erc-dcc.el, lisp/facemenu.el, lisp/gnus/message.el:
* lisp/gnus/nndoc.el, lisp/gnus/nnmaildir.el, lisp/image.el:
* lisp/international/ccl.el, lisp/international/fontset.el:
* lisp/international/mule-cmds.el, lisp/international/mule.el:
* lisp/json.el, lisp/mail/binhex.el, lisp/mail/rmail.el:
* lisp/mail/uudecode.el, lisp/md4.el, lisp/net/dns.el:
* lisp/net/ntlm.el, lisp/net/sasl.el, lisp/net/socks.el:
* lisp/net/tramp.el, lisp/obsolete/levents.el:
* lisp/obsolete/pgg-parse.el, lisp/org/org.el:
* lisp/org/ox-publish.el, lisp/progmodes/cc-defs.el:
* lisp/progmodes/ebnf2ps.el, lisp/progmodes/hideif.el:
* lisp/ps-bdf.el, lisp/ps-print.el, lisp/simple.el:
* lisp/tar-mode.el, lisp/term/common-win.el:
* lisp/term/tty-colors.el, lisp/term/xterm.el, lisp/vc/vc-git.el:
* lisp/vc/vc-hg.el, lisp/x-dnd.el, test/src/data-tests.el:
Prefer ash to lsh when either will do.
Diffstat (limited to 'lisp/net')
| -rw-r--r-- | lisp/net/dns.el | 24 | ||||
| -rw-r--r-- | lisp/net/ntlm.el | 44 | ||||
| -rw-r--r-- | lisp/net/sasl.el | 6 | ||||
| -rw-r--r-- | lisp/net/socks.el | 4 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 14 |
5 files changed, 46 insertions, 46 deletions
diff --git a/lisp/net/dns.el b/lisp/net/dns.el index 057ae3219ee..b3b430d2ba8 100644 --- a/lisp/net/dns.el +++ b/lisp/net/dns.el | |||
| @@ -117,7 +117,7 @@ updated. Set this variable to t to disable the check.") | |||
| 117 | length) | 117 | length) |
| 118 | (while (not ended) | 118 | (while (not ended) |
| 119 | (setq length (dns-read-bytes 1)) | 119 | (setq length (dns-read-bytes 1)) |
| 120 | (if (= 192 (logand length (lsh 3 6))) | 120 | (if (= 192 (logand length (ash 3 6))) |
| 121 | (let ((offset (+ (* (logand 63 length) 256) | 121 | (let ((offset (+ (* (logand 63 length) 256) |
| 122 | (dns-read-bytes 1)))) | 122 | (dns-read-bytes 1)))) |
| 123 | (save-excursion | 123 | (save-excursion |
| @@ -144,17 +144,17 @@ If TCP-P, the first two bytes of the package with be the length field." | |||
| 144 | (dns-write-bytes (dns-get 'id spec) 2) | 144 | (dns-write-bytes (dns-get 'id spec) 2) |
| 145 | (dns-write-bytes | 145 | (dns-write-bytes |
| 146 | (logior | 146 | (logior |
| 147 | (lsh (if (dns-get 'response-p spec) 1 0) -7) | 147 | (ash (if (dns-get 'response-p spec) 1 0) 7) |
| 148 | (lsh | 148 | (ash |
| 149 | (cond | 149 | (cond |
| 150 | ((eq (dns-get 'opcode spec) 'query) 0) | 150 | ((eq (dns-get 'opcode spec) 'query) 0) |
| 151 | ((eq (dns-get 'opcode spec) 'inverse-query) 1) | 151 | ((eq (dns-get 'opcode spec) 'inverse-query) 1) |
| 152 | ((eq (dns-get 'opcode spec) 'status) 2) | 152 | ((eq (dns-get 'opcode spec) 'status) 2) |
| 153 | (t (error "No such opcode: %s" (dns-get 'opcode spec)))) | 153 | (t (error "No such opcode: %s" (dns-get 'opcode spec)))) |
| 154 | -3) | 154 | 3) |
| 155 | (lsh (if (dns-get 'authoritative-p spec) 1 0) -2) | 155 | (ash (if (dns-get 'authoritative-p spec) 1 0) 2) |
| 156 | (lsh (if (dns-get 'truncated-p spec) 1 0) -1) | 156 | (ash (if (dns-get 'truncated-p spec) 1 0) 1) |
| 157 | (lsh (if (dns-get 'recursion-desired-p spec) 1 0) 0))) | 157 | (ash (if (dns-get 'recursion-desired-p spec) 1 0) 0))) |
| 158 | (dns-write-bytes | 158 | (dns-write-bytes |
| 159 | (cond | 159 | (cond |
| 160 | ((eq (dns-get 'response-code spec) 'no-error) 0) | 160 | ((eq (dns-get 'response-code spec) 'no-error) 0) |
| @@ -198,20 +198,20 @@ If TCP-P, the first two bytes of the package with be the length field." | |||
| 198 | (goto-char (point-min)) | 198 | (goto-char (point-min)) |
| 199 | (push (list 'id (dns-read-bytes 2)) spec) | 199 | (push (list 'id (dns-read-bytes 2)) spec) |
| 200 | (let ((byte (dns-read-bytes 1))) | 200 | (let ((byte (dns-read-bytes 1))) |
| 201 | (push (list 'response-p (if (zerop (logand byte (lsh 1 7))) nil t)) | 201 | (push (list 'response-p (if (zerop (logand byte (ash 1 7))) nil t)) |
| 202 | spec) | 202 | spec) |
| 203 | (let ((opcode (logand byte (lsh 7 3)))) | 203 | (let ((opcode (logand byte (ash 7 3)))) |
| 204 | (push (list 'opcode | 204 | (push (list 'opcode |
| 205 | (cond ((eq opcode 0) 'query) | 205 | (cond ((eq opcode 0) 'query) |
| 206 | ((eq opcode 1) 'inverse-query) | 206 | ((eq opcode 1) 'inverse-query) |
| 207 | ((eq opcode 2) 'status))) | 207 | ((eq opcode 2) 'status))) |
| 208 | spec)) | 208 | spec)) |
| 209 | (push (list 'authoritative-p (if (zerop (logand byte (lsh 1 2))) | 209 | (push (list 'authoritative-p (if (zerop (logand byte (ash 1 2))) |
| 210 | nil t)) spec) | 210 | nil t)) spec) |
| 211 | (push (list 'truncated-p (if (zerop (logand byte (lsh 1 2))) nil t)) | 211 | (push (list 'truncated-p (if (zerop (logand byte (ash 1 2))) nil t)) |
| 212 | spec) | 212 | spec) |
| 213 | (push (list 'recursion-desired-p | 213 | (push (list 'recursion-desired-p |
| 214 | (if (zerop (logand byte (lsh 1 0))) nil t)) spec)) | 214 | (if (zerop (logand byte (ash 1 0))) nil t)) spec)) |
| 215 | (let ((rc (logand (dns-read-bytes 1) 15))) | 215 | (let ((rc (logand (dns-read-bytes 1) 15))) |
| 216 | (push (list 'response-code | 216 | (push (list 'response-code |
| 217 | (cond | 217 | (cond |
diff --git a/lisp/net/ntlm.el b/lisp/net/ntlm.el index 8366bc14e95..217f0b859f2 100644 --- a/lisp/net/ntlm.el +++ b/lisp/net/ntlm.el | |||
| @@ -411,9 +411,9 @@ a string KEY of length 8. FORW is t or nil." | |||
| 411 | (key2 (ntlm-smb-str-to-key key)) | 411 | (key2 (ntlm-smb-str-to-key key)) |
| 412 | (i 0) aa) | 412 | (i 0) aa) |
| 413 | (while (< i 64) | 413 | (while (< i 64) |
| 414 | (unless (zerop (logand (aref in (/ i 8)) (lsh 1 (- 7 (% i 8))))) | 414 | (unless (zerop (logand (aref in (/ i 8)) (ash 1 (- 7 (% i 8))))) |
| 415 | (aset inb i 1)) | 415 | (aset inb i 1)) |
| 416 | (unless (zerop (logand (aref key2 (/ i 8)) (lsh 1 (- 7 (% i 8))))) | 416 | (unless (zerop (logand (aref key2 (/ i 8)) (ash 1 (- 7 (% i 8))))) |
| 417 | (aset keyb i 1)) | 417 | (aset keyb i 1)) |
| 418 | (setq i (1+ i))) | 418 | (setq i (1+ i))) |
| 419 | (setq outb (ntlm-smb-dohash inb keyb forw)) | 419 | (setq outb (ntlm-smb-dohash inb keyb forw)) |
| @@ -422,7 +422,7 @@ a string KEY of length 8. FORW is t or nil." | |||
| 422 | (unless (zerop (aref outb i)) | 422 | (unless (zerop (aref outb i)) |
| 423 | (setq aa (aref out (/ i 8))) | 423 | (setq aa (aref out (/ i 8))) |
| 424 | (aset out (/ i 8) | 424 | (aset out (/ i 8) |
| 425 | (logior aa (lsh 1 (- 7 (% i 8)))))) | 425 | (logior aa (ash 1 (- 7 (% i 8)))))) |
| 426 | (setq i (1+ i))) | 426 | (setq i (1+ i))) |
| 427 | out)) | 427 | out)) |
| 428 | 428 | ||
| @@ -430,28 +430,28 @@ a string KEY of length 8. FORW is t or nil." | |||
| 430 | "Return a string of length 8 for the given string STR of length 7." | 430 | "Return a string of length 8 for the given string STR of length 7." |
| 431 | (let ((key (make-string 8 0)) | 431 | (let ((key (make-string 8 0)) |
| 432 | (i 7)) | 432 | (i 7)) |
| 433 | (aset key 0 (lsh (aref str 0) -1)) | 433 | (aset key 0 (ash (aref str 0) -1)) |
| 434 | (aset key 1 (logior | 434 | (aset key 1 (logior |
| 435 | (lsh (logand (aref str 0) 1) 6) | 435 | (ash (logand (aref str 0) 1) 6) |
| 436 | (lsh (aref str 1) -2))) | 436 | (ash (aref str 1) -2))) |
| 437 | (aset key 2 (logior | 437 | (aset key 2 (logior |
| 438 | (lsh (logand (aref str 1) 3) 5) | 438 | (ash (logand (aref str 1) 3) 5) |
| 439 | (lsh (aref str 2) -3))) | 439 | (ash (aref str 2) -3))) |
| 440 | (aset key 3 (logior | 440 | (aset key 3 (logior |
| 441 | (lsh (logand (aref str 2) 7) 4) | 441 | (ash (logand (aref str 2) 7) 4) |
| 442 | (lsh (aref str 3) -4))) | 442 | (ash (aref str 3) -4))) |
| 443 | (aset key 4 (logior | 443 | (aset key 4 (logior |
| 444 | (lsh (logand (aref str 3) 15) 3) | 444 | (ash (logand (aref str 3) 15) 3) |
| 445 | (lsh (aref str 4) -5))) | 445 | (ash (aref str 4) -5))) |
| 446 | (aset key 5 (logior | 446 | (aset key 5 (logior |
| 447 | (lsh (logand (aref str 4) 31) 2) | 447 | (ash (logand (aref str 4) 31) 2) |
| 448 | (lsh (aref str 5) -6))) | 448 | (ash (aref str 5) -6))) |
| 449 | (aset key 6 (logior | 449 | (aset key 6 (logior |
| 450 | (lsh (logand (aref str 5) 63) 1) | 450 | (ash (logand (aref str 5) 63) 1) |
| 451 | (lsh (aref str 6) -7))) | 451 | (ash (aref str 6) -7))) |
| 452 | (aset key 7 (logand (aref str 6) 127)) | 452 | (aset key 7 (logand (aref str 6) 127)) |
| 453 | (while (>= i 0) | 453 | (while (>= i 0) |
| 454 | (aset key i (lsh (aref key i) 1)) | 454 | (aset key i (ash (aref key i) 1)) |
| 455 | (setq i (1- i))) | 455 | (setq i (1- i))) |
| 456 | key)) | 456 | key)) |
| 457 | 457 | ||
| @@ -619,16 +619,16 @@ backward." | |||
| 619 | (setq j 0) | 619 | (setq j 0) |
| 620 | (while (< j 8) | 620 | (while (< j 8) |
| 621 | (setq bj (aref b j)) | 621 | (setq bj (aref b j)) |
| 622 | (setq m (logior (lsh (aref bj 0) 1) (aref bj 5))) | 622 | (setq m (logior (ash (aref bj 0) 1) (aref bj 5))) |
| 623 | (setq n (logior (lsh (aref bj 1) 3) | 623 | (setq n (logior (ash (aref bj 1) 3) |
| 624 | (lsh (aref bj 2) 2) | 624 | (ash (aref bj 2) 2) |
| 625 | (lsh (aref bj 3) 1) | 625 | (ash (aref bj 3) 1) |
| 626 | (aref bj 4))) | 626 | (aref bj 4))) |
| 627 | (setq k 0) | 627 | (setq k 0) |
| 628 | (setq sbox-jmn (aref (aref (aref ntlm-smb-sbox j) m) n)) | 628 | (setq sbox-jmn (aref (aref (aref ntlm-smb-sbox j) m) n)) |
| 629 | (while (< k 4) | 629 | (while (< k 4) |
| 630 | (aset bj k | 630 | (aset bj k |
| 631 | (if (zerop (logand sbox-jmn (lsh 1 (- 3 k)))) | 631 | (if (zerop (logand sbox-jmn (ash 1 (- 3 k)))) |
| 632 | 0 1)) | 632 | 0 1)) |
| 633 | (setq k (1+ k))) | 633 | (setq k (1+ k))) |
| 634 | (setq j (1+ j))) | 634 | (setq j (1+ j))) |
diff --git a/lisp/net/sasl.el b/lisp/net/sasl.el index b4f0fffc716..ca0b66b2fb6 100644 --- a/lisp/net/sasl.el +++ b/lisp/net/sasl.el | |||
| @@ -183,7 +183,7 @@ It contain at least 64 bits of entropy." | |||
| 183 | ;; Don't use microseconds from (current-time), they may be unsupported. | 183 | ;; Don't use microseconds from (current-time), they may be unsupported. |
| 184 | ;; Instead we use this randomly inited counter. | 184 | ;; Instead we use this randomly inited counter. |
| 185 | (setq sasl-unique-id-char | 185 | (setq sasl-unique-id-char |
| 186 | (% (1+ (or sasl-unique-id-char (logand (random) (1- (lsh 1 20))))) | 186 | (% (1+ (or sasl-unique-id-char (logand (random) (1- (ash 1 20))))) |
| 187 | ;; (current-time) returns 16-bit ints, | 187 | ;; (current-time) returns 16-bit ints, |
| 188 | ;; and 2^16*25 just fits into 4 digits i base 36. | 188 | ;; and 2^16*25 just fits into 4 digits i base 36. |
| 189 | (* 25 25))) | 189 | (* 25 25))) |
| @@ -191,10 +191,10 @@ It contain at least 64 bits of entropy." | |||
| 191 | (concat | 191 | (concat |
| 192 | (sasl-unique-id-number-base36 | 192 | (sasl-unique-id-number-base36 |
| 193 | (+ (car tm) | 193 | (+ (car tm) |
| 194 | (lsh (% sasl-unique-id-char 25) 16)) 4) | 194 | (ash (% sasl-unique-id-char 25) 16)) 4) |
| 195 | (sasl-unique-id-number-base36 | 195 | (sasl-unique-id-number-base36 |
| 196 | (+ (nth 1 tm) | 196 | (+ (nth 1 tm) |
| 197 | (lsh (/ sasl-unique-id-char 25) 16)) 4)))) | 197 | (ash (/ sasl-unique-id-char 25) 16)) 4)))) |
| 198 | 198 | ||
| 199 | (defun sasl-unique-id-number-base36 (num len) | 199 | (defun sasl-unique-id-number-base36 (num len) |
| 200 | (if (if (< len 0) | 200 | (if (if (< len 0) |
diff --git a/lisp/net/socks.el b/lisp/net/socks.el index 4a3b13282cf..5ee6eea933f 100644 --- a/lisp/net/socks.el +++ b/lisp/net/socks.el | |||
| @@ -420,7 +420,7 @@ | |||
| 420 | (unibyte-string | 420 | (unibyte-string |
| 421 | version ; version | 421 | version ; version |
| 422 | command ; command | 422 | command ; command |
| 423 | (lsh port -8) ; port, high byte | 423 | (ash port -8) ; port, high byte |
| 424 | (logand port #xff)) ; port, low byte | 424 | (logand port #xff)) ; port, low byte |
| 425 | addr ; address | 425 | addr ; address |
| 426 | (user-full-name) ; username | 426 | (user-full-name) ; username |
| @@ -434,7 +434,7 @@ | |||
| 434 | atype) ; address type | 434 | atype) ; address type |
| 435 | addr ; address | 435 | addr ; address |
| 436 | (unibyte-string | 436 | (unibyte-string |
| 437 | (lsh port -8) ; port, high byte | 437 | (ash port -8) ; port, high byte |
| 438 | (logand port #xff))))) ; port, low byte | 438 | (logand port #xff))))) ; port, low byte |
| 439 | (t | 439 | (t |
| 440 | (error "Unknown protocol version: %d" version))) | 440 | (error "Unknown protocol version: %d" version))) |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 1af2defd586..8e6c9118509 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -4108,13 +4108,13 @@ This is used to map a mode number to a permission string.") | |||
| 4108 | (defun tramp-file-mode-from-int (mode) | 4108 | (defun tramp-file-mode-from-int (mode) |
| 4109 | "Turn an integer representing a file mode into an ls(1)-like string." | 4109 | "Turn an integer representing a file mode into an ls(1)-like string." |
| 4110 | (let ((type (cdr | 4110 | (let ((type (cdr |
| 4111 | (assoc (logand (lsh mode -12) 15) tramp-file-mode-type-map))) | 4111 | (assoc (logand (ash mode -12) 15) tramp-file-mode-type-map))) |
| 4112 | (user (logand (lsh mode -6) 7)) | 4112 | (user (logand (ash mode -6) 7)) |
| 4113 | (group (logand (lsh mode -3) 7)) | 4113 | (group (logand (ash mode -3) 7)) |
| 4114 | (other (logand (lsh mode -0) 7)) | 4114 | (other (logand (ash mode -0) 7)) |
| 4115 | (suid (> (logand (lsh mode -9) 4) 0)) | 4115 | (suid (> (logand (ash mode -9) 4) 0)) |
| 4116 | (sgid (> (logand (lsh mode -9) 2) 0)) | 4116 | (sgid (> (logand (ash mode -9) 2) 0)) |
| 4117 | (sticky (> (logand (lsh mode -9) 1) 0))) | 4117 | (sticky (> (logand (ash mode -9) 1) 0))) |
| 4118 | (setq user (tramp-file-mode-permissions user suid "s")) | 4118 | (setq user (tramp-file-mode-permissions user suid "s")) |
| 4119 | (setq group (tramp-file-mode-permissions group sgid "s")) | 4119 | (setq group (tramp-file-mode-permissions group sgid "s")) |
| 4120 | (setq other (tramp-file-mode-permissions other sticky "t")) | 4120 | (setq other (tramp-file-mode-permissions other sticky "t")) |