#3880 p11_child: Fix warning cast discards ‘const’ qualifier from pointer target type
Merged by jhrozek. Opened by lslebodn.
SSSD/ lslebodn/sssd p11_child_warning  into  master

Download 3880.patch

The function process_responder had parameter port defined as const and
it was used in macro BIO_set_conn_port which cast 2nd parameter to
(char*)

# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1, \
(char *)(port))

src/p11_child/p11_child_openssl.c: In function ‘process_responder’:
src/p11_child/p11_child_openssl.c:157:9: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
BIO_set_conn_port(cbio, port);
^~~~~~~~~~~~~~~~~

@sbose,
could you check this fix?

rebased onto f173e1f0185c64d4c9a17d43b9614732b3295cf8

Hi @lslebodn,

thanks for reporting this issue. Internally OpenSSL treats the value as const char* as well but in some steps they treat it as void * to pass the pointer through some common calls and macros.

Given that I think a fix like BIO_set_conn_port(cbio, discard_const(port)); would be more suitable. Do you agree?

bye,
Sumit

The variable port is declared without const modifier in the function do_ocsp.
https://pagure.io/SSSD/sssd/blob/master/f/src/p11_child/p11_child_openssl.c#_201

I assume the reason is because of prototype of function OCSP_parse_url which set value to the variableport

sh$ grep -Rn -C1 OCSP_parse_url /usr/include/
/usr/include/openssl/ocsp.h-231-
/usr/include/openssl/ocsp.h:232:int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath,
/usr/include/openssl/ocsp.h-233-                   int *pssl);

https://pagure.io/SSSD/sssd/blob/master/f/src/p11_child/p11_child_openssl.c#_229

Then the variable is used in function process_responder which has parameter defined with const modifier
https://pagure.io/SSSD/sssd/blob/master/f/src/p11_child/p11_child_openssl.c#_285
https://pagure.io/SSSD/sssd/blob/master/f/src/p11_child/p11_child_openssl.c#_144

And then it is passed to the macro(function) BIO_set_conn_port which expect argument without const modifier because there is a cast to char *.
https://pagure.io/SSSD/sssd/blob/master/f/src/p11_child/p11_child_openssl.c#_157

So ATM we have char * -> const char * -> (char*)port.
Maybe API of openssl is not ideal and might use that as const char* internally. But we should use what we have char * -> char * -> (char*)port.

Adding const modifier and then removing it with the macro discard_const does not improve anything. char * -> const char * -> (char*)discard_const_p(char, port).

And as it was mentioned in the descriprion of this PR,

@sbose thank you for review and I'm sorry for longer response.

Ok, so let's wait until OpenSSL will change its API. ACK.

Commit 5e703d3d fixes this pull-request

Pull-Request has been merged by jhrozek

Metadata