diff options
| author | F. Jason Park | 2021-02-05 19:41:04 -0800 |
|---|---|---|
| committer | Eli Zaretskii | 2021-02-20 13:03:12 +0200 |
| commit | 43703a06b9ea31b86c46bef7cb488ea885569ddc (patch) | |
| tree | c4f227467b7a051fb9a93d10fee99726cdbf47ad | |
| parent | acf71609200e56ef28f31be0df33ea3905eb2188 (diff) | |
| download | emacs-43703a06b9ea31b86c46bef7cb488ea885569ddc.tar.gz emacs-43703a06b9ea31b86c46bef7cb488ea885569ddc.zip | |
Use raw bytes for SOCKS 4 IP addresses
* lisp/net/socks.el: (socks--open-network-stream, socks-send-command):
* test/lisp/net/socks-tests.el: (socks-tests-v4-basic): (Bug#46342).
| -rw-r--r-- | lisp/net/socks.el | 4 | ||||
| -rw-r--r-- | test/lisp/net/socks-tests.el | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lisp/net/socks.el b/lisp/net/socks.el index 96fafc826b8..1da1d31d678 100644 --- a/lisp/net/socks.el +++ b/lisp/net/socks.el | |||
| @@ -390,6 +390,8 @@ | |||
| 390 | proc))) | 390 | proc))) |
| 391 | 391 | ||
| 392 | (defun socks-send-command (proc command atype address port) | 392 | (defun socks-send-command (proc command atype address port) |
| 393 | "Send COMMAND to SOCKS service PROC for proxying ADDRESS and PORT. | ||
| 394 | When ATYPE indicates an IP, param ADDRESS must be given as raw bytes." | ||
| 393 | (let ((addr (cond | 395 | (let ((addr (cond |
| 394 | ((or (= atype socks-address-type-v4) | 396 | ((or (= atype socks-address-type-v4) |
| 395 | (= atype socks-address-type-v6)) | 397 | (= atype socks-address-type-v6)) |
| @@ -528,7 +530,7 @@ | |||
| 528 | (setq host (socks-nslookup-host host)) | 530 | (setq host (socks-nslookup-host host)) |
| 529 | (if (not (listp host)) | 531 | (if (not (listp host)) |
| 530 | (error "Could not get IP address for: %s" host)) | 532 | (error "Could not get IP address for: %s" host)) |
| 531 | (setq host (apply #'format "%c%c%c%c" host)) | 533 | (setq host (apply #'unibyte-string host)) |
| 532 | socks-address-type-v4) | 534 | socks-address-type-v4) |
| 533 | (t | 535 | (t |
| 534 | socks-address-type-name)))) | 536 | socks-address-type-name)))) |
diff --git a/test/lisp/net/socks-tests.el b/test/lisp/net/socks-tests.el index 340a42d79cc..9a2dcba9daf 100644 --- a/test/lisp/net/socks-tests.el +++ b/test/lisp/net/socks-tests.el | |||
| @@ -185,6 +185,26 @@ Vectors must match verbatim. Strings are considered regex patterns.") | |||
| 185 | (kill-buffer buf) | 185 | (kill-buffer buf) |
| 186 | (ignore url-gateway-method))) | 186 | (ignore url-gateway-method))) |
| 187 | 187 | ||
| 188 | ;; Unlike curl, socks.el includes the ID field (but otherwise matches): | ||
| 189 | ;; $ curl --proxy socks4://127.0.0.1:1080 example.com | ||
| 190 | |||
| 191 | (ert-deftest socks-tests-v4-basic () | ||
| 192 | "Show correct preparation of SOCKS4 connect command (Bug#46342)." | ||
| 193 | (let ((socks-server '("server" "127.0.0.1" 10079 4)) | ||
| 194 | (url-user-agent "Test/4-basic") | ||
| 195 | (socks-tests-canned-server-patterns | ||
| 196 | `(([4 1 0 80 93 184 216 34 ?f ?o ?o 0] . [0 90 0 0 0 0 0 0]) | ||
| 197 | ,socks-tests--hello-world-http-request-pattern)) | ||
| 198 | socks-nslookup-program) | ||
| 199 | (ert-info ("Make HTTP request over SOCKS4") | ||
| 200 | (cl-letf (((symbol-function 'socks-nslookup-host) | ||
| 201 | (lambda (host) | ||
| 202 | (should (equal host "example.com")) | ||
| 203 | (list 93 184 216 34))) | ||
| 204 | ((symbol-function 'user-full-name) | ||
| 205 | (lambda () "foo"))) | ||
| 206 | (socks-tests-perform-hello-world-http-request))))) | ||
| 207 | |||
| 188 | ;; Replace first pattern below with ([5 3 0 1 2] . [5 2]) to validate | 208 | ;; Replace first pattern below with ([5 3 0 1 2] . [5 2]) to validate |
| 189 | ;; against curl 7.71 with the following options: | 209 | ;; against curl 7.71 with the following options: |
| 190 | ;; $ curl --verbose -U foo:bar --proxy socks5h://127.0.0.1:10080 example.com | 210 | ;; $ curl --verbose -U foo:bar --proxy socks5h://127.0.0.1:10080 example.com |