sk_TYPE_find*() on built-in stack types still requires a non-const STACK_OF

Aperta Adatta ai principianti
#33,707 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@bob-beck ci sta già lavorando.

Dal 13/11/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, perl
Ambito
api, build-system

Direzione di ricerca

Le macro find sono generate da util/perl/OpenSSL/stackhash.pm; confronta come emette sk_TYPE_find* con i casi sk_TYPE_num e sk_TYPE_value, che usano già ossl_check_const_TYPE_sk_type(). Passa le tre macro find a quell'helper, poi esegui make build_generated e ricompila il reproducer dell'issue. È completato quando compila senza l'avviso di const-discard sia con gcc sia con clang.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

branch: 4.0 branch: 4.1 branch: master triaged: bug

#20135 and #28532 made it so that OPENSSL_sk_find(), OPENSSL_sk_find_ex(), and OPENSSL_sk_find_all() take a const OPENSSL_STACK * and documented as such.

However, stack types declared with generate_stack_macros() / generate_const_stack_macros() get their sk_TYPE_find* macros from util/perl/OpenSSL/stackhash.pm, which still passes the stack through the non-const ossl_check_TYPE_sk_type(), so for these types the functions must take a non-const STACK_OF(TYPE) *, contrary to the documentation.

Version: openssl-4.1.0, headers generated from a source checkout (./Configure && make build_generated).

Reproducer:

#include <openssl/ssl.h>

int find_cipher(const STACK_OF(SSL_CIPHER) *sk, const SSL_CIPHER *c) {
    return sk_SSL_CIPHER_find(sk, c);
}
$ gcc -c -Wall -I include /tmp/openssl_repro.c 
In file included from /tmp/openssl_repro.c:1:
/tmp/openssl_repro.c: In function ‘find_cipher’:
/tmp/openssl_repro.c:4:31: warning: passing argument 1 of ‘ossl_check_SSL_CIPHER_sk_type’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
    4 |     return sk_SSL_CIPHER_find(sk, c);
      |                               ^~
include/openssl/ssl.h:1109:83: note: in definition of macro ‘sk_SSL_CIPHER_find’
 1109 | #define sk_SSL_CIPHER_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
      |                                                                                   ^~
In file included from include/openssl/crypto.h:36,
                 from include/openssl/comp.h:25,
                 from include/openssl/ssl.h:31:
include/openssl/safestack.h:67:91: note: expected ‘struct stack_st_SSL_CIPHER *’ but argument is of type ‘const struct stack_st_SSL_CIPHER *’
   67 |     static ossl_unused ossl_inline OPENSSL_STACK *ossl_check_##t1##_sk_type(STACK_OF(t1) *sk)                            \
      |                                                                                           ^
include/openssl/ssl.h:1070:1: note: in expansion of macro ‘SKM_DEFINE_STACK_OF_INTERNAL’
 1070 | SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

$ clang -c -Wall -I include /tmp/openssl_repro.c
/tmp/openssl_repro.c:4:31: warning: passing 'const struct stack_st_SSL_CIPHER *' to parameter of type 'struct stack_st_SSL_CIPHER *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
    4 |     return sk_SSL_CIPHER_find(sk, c);
      |                               ^~
include/openssl/ssl.h:1070:1: note: passing argument to parameter 'sk' here
 1070 | SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER)
      | ^
include/openssl/safestack.h:67:91: note: expanded from macro 'SKM_DEFINE_STACK_OF_INTERNAL'
   67 |     static ossl_unused ossl_inline OPENSSL_STACK *ossl_check_##t1##_sk_type(STACK_OF(t1) *sk)                            \
      |                                                                                           ^
1 warning generated.

(gcc 15.2.0, clang 21.1.8)

Expected: compiles cleanly

Suggested fix: use the existing ossl_check_const_TYPE_sk_type() for the three find macros in stackhash.pm, as is already done for sk_TYPE_num, sk_TYPE_value and sk_TYPE_is_sorted:

Context: this came up while preparing various callers for BoringSSL's change to make SSL_get_ciphers() return a const pointer (https://crbug.com/550501994), where in cpython there's a neighboring SSL_get_client_ciphers() result passed to sk_SSL_CIPHER_find() that surprisingly can't be made const due to this.

Lingua principale
C
Stelle
31.4k
Fork
11.6k
Merge medio
20m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openssl/openssl

Tutte le issue di openssl/openssl

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.