diff options
| author | Eli Zaretskii | 2018-07-17 19:58:27 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2018-07-17 19:58:27 +0300 |
| commit | a4767a662bf360b489059e2cbf028138f2399252 (patch) | |
| tree | e10ff010fb69caa7f5080ff07aa16200945ba655 | |
| parent | 90110f8499c5b3e26c67d3e15cc8dccd9ef057cf (diff) | |
| download | emacs-a4767a662bf360b489059e2cbf028138f2399252.tar.gz emacs-a4767a662bf360b489059e2cbf028138f2399252.zip | |
Avoid assertion violations in gnutls.c
* src/gnutls.c (Fgnutls_hash_digest, gnutls_symmetric)
(Fgnutls_hash_mac): Check CONSP before invoking XCDR. (Bug#32187)
Report values of invalid arguments when signaling an error.
| -rw-r--r-- | src/gnutls.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/gnutls.c b/src/gnutls.c index 903393fed18..461260e27f4 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -2024,7 +2024,14 @@ gnutls_symmetric (bool encrypting, Lisp_Object cipher, | |||
| 2024 | cipher = intern (SSDATA (cipher)); | 2024 | cipher = intern (SSDATA (cipher)); |
| 2025 | 2025 | ||
| 2026 | if (SYMBOLP (cipher)) | 2026 | if (SYMBOLP (cipher)) |
| 2027 | info = XCDR (Fassq (cipher, Fgnutls_ciphers ())); | 2027 | { |
| 2028 | info = Fassq (cipher, Fgnutls_ciphers ()); | ||
| 2029 | if (!CONSP (info)) | ||
| 2030 | xsignal2 (Qerror, | ||
| 2031 | build_string ("GnuTLS cipher is invalid or not found"), | ||
| 2032 | cipher); | ||
| 2033 | info = XCDR (info); | ||
| 2034 | } | ||
| 2028 | else if (TYPE_RANGED_INTEGERP (gnutls_cipher_algorithm_t, cipher)) | 2035 | else if (TYPE_RANGED_INTEGERP (gnutls_cipher_algorithm_t, cipher)) |
| 2029 | gca = XINT (cipher); | 2036 | gca = XINT (cipher); |
| 2030 | else | 2037 | else |
| @@ -2039,7 +2046,8 @@ gnutls_symmetric (bool encrypting, Lisp_Object cipher, | |||
| 2039 | 2046 | ||
| 2040 | ptrdiff_t key_size = gnutls_cipher_get_key_size (gca); | 2047 | ptrdiff_t key_size = gnutls_cipher_get_key_size (gca); |
| 2041 | if (key_size == 0) | 2048 | if (key_size == 0) |
| 2042 | error ("GnuTLS cipher is invalid or not found"); | 2049 | xsignal2 (Qerror, |
| 2050 | build_string ("GnuTLS cipher is invalid or not found"), cipher); | ||
| 2043 | 2051 | ||
| 2044 | ptrdiff_t kstart_byte, kend_byte; | 2052 | ptrdiff_t kstart_byte, kend_byte; |
| 2045 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); | 2053 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); |
| @@ -2295,7 +2303,14 @@ itself. */) | |||
| 2295 | hash_method = intern (SSDATA (hash_method)); | 2303 | hash_method = intern (SSDATA (hash_method)); |
| 2296 | 2304 | ||
| 2297 | if (SYMBOLP (hash_method)) | 2305 | if (SYMBOLP (hash_method)) |
| 2298 | info = XCDR (Fassq (hash_method, Fgnutls_macs ())); | 2306 | { |
| 2307 | info = Fassq (hash_method, Fgnutls_macs ()); | ||
| 2308 | if (!CONSP (info)) | ||
| 2309 | xsignal2 (Qerror, | ||
| 2310 | build_string ("GnuTLS MAC-method is invalid or not found"), | ||
| 2311 | hash_method); | ||
| 2312 | info = XCDR (info); | ||
| 2313 | } | ||
| 2299 | else if (TYPE_RANGED_INTEGERP (gnutls_mac_algorithm_t, hash_method)) | 2314 | else if (TYPE_RANGED_INTEGERP (gnutls_mac_algorithm_t, hash_method)) |
| 2300 | gma = XINT (hash_method); | 2315 | gma = XINT (hash_method); |
| 2301 | else | 2316 | else |
| @@ -2310,7 +2325,9 @@ itself. */) | |||
| 2310 | 2325 | ||
| 2311 | ptrdiff_t digest_length = gnutls_hmac_get_len (gma); | 2326 | ptrdiff_t digest_length = gnutls_hmac_get_len (gma); |
| 2312 | if (digest_length == 0) | 2327 | if (digest_length == 0) |
| 2313 | error ("GnuTLS MAC-method is invalid or not found"); | 2328 | xsignal2 (Qerror, |
| 2329 | build_string ("GnuTLS MAC-method is invalid or not found"), | ||
| 2330 | hash_method); | ||
| 2314 | 2331 | ||
| 2315 | ptrdiff_t kstart_byte, kend_byte; | 2332 | ptrdiff_t kstart_byte, kend_byte; |
| 2316 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); | 2333 | const char *kdata = extract_data_from_object (key, &kstart_byte, &kend_byte); |
| @@ -2376,7 +2393,14 @@ the number itself. */) | |||
| 2376 | digest_method = intern (SSDATA (digest_method)); | 2393 | digest_method = intern (SSDATA (digest_method)); |
| 2377 | 2394 | ||
| 2378 | if (SYMBOLP (digest_method)) | 2395 | if (SYMBOLP (digest_method)) |
| 2379 | info = XCDR (Fassq (digest_method, Fgnutls_digests ())); | 2396 | { |
| 2397 | info = Fassq (digest_method, Fgnutls_digests ()); | ||
| 2398 | if (!CONSP (info)) | ||
| 2399 | xsignal2 (Qerror, | ||
| 2400 | build_string ("GnuTLS digest-method is invalid or not found"), | ||
| 2401 | digest_method); | ||
| 2402 | info = XCDR (info); | ||
| 2403 | } | ||
| 2380 | else if (TYPE_RANGED_INTEGERP (gnutls_digest_algorithm_t, digest_method)) | 2404 | else if (TYPE_RANGED_INTEGERP (gnutls_digest_algorithm_t, digest_method)) |
| 2381 | gda = XINT (digest_method); | 2405 | gda = XINT (digest_method); |
| 2382 | else | 2406 | else |
| @@ -2391,7 +2415,9 @@ the number itself. */) | |||
| 2391 | 2415 | ||
| 2392 | ptrdiff_t digest_length = gnutls_hash_get_len (gda); | 2416 | ptrdiff_t digest_length = gnutls_hash_get_len (gda); |
| 2393 | if (digest_length == 0) | 2417 | if (digest_length == 0) |
| 2394 | error ("GnuTLS digest-method is invalid or not found"); | 2418 | xsignal2 (Qerror, |
| 2419 | build_string ("GnuTLS digest-method is invalid or not found"), | ||
| 2420 | digest_method); | ||
| 2395 | 2421 | ||
| 2396 | gnutls_hash_hd_t hash; | 2422 | gnutls_hash_hd_t hash; |
| 2397 | int ret = gnutls_hash_init (&hash, gda); | 2423 | int ret = gnutls_hash_init (&hash, gda); |