diff options
| author | Robert Pluim | 2019-11-18 10:57:55 +0100 |
|---|---|---|
| committer | Robert Pluim | 2019-11-19 13:36:07 +0100 |
| commit | cf0a76a43831105d74b54f0e50f77eb60460fbea (patch) | |
| tree | ae3826dddc319ea19d61ef26fb8e997f2ac5e9e7 | |
| parent | 067a42f8dd2ce19de3203605ee8c1c08aa192580 (diff) | |
| download | emacs-cf0a76a43831105d74b54f0e50f77eb60460fbea.tar.gz emacs-cf0a76a43831105d74b54f0e50f77eb60460fbea.zip | |
Don't error when comparing IPv4 and IPv6 addresses
* lisp/net/nsm.el (nsm-network-same-subnet): Compare lengths of
local-ip and ip; different lengths can never match.
(nsm-should-check): Chop port off end of address.
| -rw-r--r-- | lisp/net/nsm.el | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el index c47ef55a6f4..205b7974883 100644 --- a/lisp/net/nsm.el +++ b/lisp/net/nsm.el | |||
| @@ -204,17 +204,21 @@ LOCAL-IP, MASK, and IP are specified as vectors of integers, and | |||
| 204 | are expected to have the same length. Works for both IPv4 and | 204 | are expected to have the same length. Works for both IPv4 and |
| 205 | IPv6 addresses." | 205 | IPv6 addresses." |
| 206 | (let ((matches t) | 206 | (let ((matches t) |
| 207 | (length (length local-ip))) | 207 | (ip-length (length ip)) |
| 208 | (unless (memq length '(4 5 8 9)) | 208 | (local-length (length local-ip))) |
| 209 | (unless (and (memq ip-length '(4 5 8 9)) | ||
| 210 | (memq local-length '(4 5 8 9))) | ||
| 209 | (error "Unexpected length of IP address %S" local-ip)) | 211 | (error "Unexpected length of IP address %S" local-ip)) |
| 210 | (dotimes (i length) | 212 | (if (/= ip-length local-length) |
| 211 | (setq matches (and matches | 213 | nil |
| 212 | (= | 214 | (dotimes (i local-length) |
| 213 | (logand (aref local-ip i) | 215 | (setq matches (and matches |
| 214 | (aref mask i)) | 216 | (= |
| 215 | (logand (aref ip i) | 217 | (logand (aref local-ip i) |
| 216 | (aref mask i)))))) | 218 | (aref mask i)) |
| 217 | matches)) | 219 | (logand (aref ip i) |
| 220 | (aref mask i)))))) | ||
| 221 | matches))) | ||
| 218 | 222 | ||
| 219 | (defun nsm-should-check (host) | 223 | (defun nsm-should-check (host) |
| 220 | "Determine whether NSM should check for TLS problems for HOST. | 224 | "Determine whether NSM should check for TLS problems for HOST. |
| @@ -238,7 +242,7 @@ otherwise." | |||
| 238 | (when | 242 | (when |
| 239 | (nsm-network-same-subnet (substring (car info) 0 -1) | 243 | (nsm-network-same-subnet (substring (car info) 0 -1) |
| 240 | (substring (car (cddr info)) 0 -1) | 244 | (substring (car (cddr info)) 0 -1) |
| 241 | address) | 245 | (substring address 0 -1)) |
| 242 | (setq off-net nil)))) | 246 | (setq off-net nil)))) |
| 243 | network-interface-list)) | 247 | network-interface-list)) |
| 244 | addresses)) | 248 | addresses)) |