Bug 3192 - openssh-8.2 & openssl-1.1.1d error: dereferencing pointer to incomplete type Not found struct BIO , bio->num_write
Summary: openssh-8.2 & openssl-1.1.1d error: dereferencing pointer to incomplete type ...
Status: CLOSED INVALID
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 8.2p1
Hardware: Other Linux
: P5 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-14 13:39 AEST by cun
Modified: 2021-04-23 15:02 AEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cun 2020-07-14 13:39:51 AEST
build openssh-8.2
sshkey.c:4625:27: error: dereferencing pointer to incomplete type BIO_read(bio, keybuf, bio->num_write);
bio->num_write //Not found struct BIO

cc -g -O0 -D_FORTIFY_SOURCE=2 -DDEBUG_KEXECDH  -fno-builtin-memset   -I. -I. -I/build/store/ssl//include -I/build/store/ssl/include -I/build/store/zlib/include -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -DSSHDIR=\"/etc/ssh\" -D_PATH_SSH_PROGRAM=\"/build/store/newssh/bin/ssh\" -D_PATH_SSH_ASKPASS_DEFAULT=\"/build/store/newssh/libexec/ssh-askpass\" -D_PATH_SFTP_SERVER=\"/build/store/newssh/libexec/sftp-server\" -D_PATH_SSH_KEY_SIGN=\"/build/store/newssh/libexec/ssh-keysign\" -D_PATH_SSH_PKCS11_HELPER=\"/build/store/newssh/libexec/ssh-pkcs11-helper\" -D_PATH_SSH_SK_HELPER=\"/build/store/newssh/libexec/ssh-sk-helper\" -D_PATH_SSH_PIDDIR=\"/run/\" -D_PATH_PRIVSEP_CHROOT_DIR=\"/var/empty\" -DHAVE_CONFIG_H  -c sshkey.c -o sshkey.o

sshkey.c: In function ‘sshkey_parse_private_pem_fileblob’:
sshkey.c:4625:27: error: dereferencing pointer to incomplete type
  BIO_read(bio, keybuf, bio->num_write);

---

sshkey.c code view
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/ossl_typ.h>
....
static int
sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type,
    const char *passphrase, struct sshkey **keyp)
{
	EVP_PKEY *pk = NULL;
	struct sshkey *prv = NULL;
	BIO *bio = NULL;
	int r;

	if (keyp != NULL)
		*keyp = NULL;

	if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX)
		return SSH_ERR_ALLOC_FAIL;
	if (BIO_write(bio, sshbuf_ptr(blob), sshbuf_len(blob)) !=
	    (int)sshbuf_len(blob)) {
		r = SSH_ERR_ALLOC_FAIL;
		goto out;
	}
	
	char keybuf[T_L_4] = {0};
	BIO_read(bio, keybuf, bio->num_write);
Comment 1 cun 2020-07-14 19:01:50 AEST
from openssl include inmport error
Comment 2 cun 2020-07-14 19:02:25 AEST
build ok!
Comment 3 Darren Tucker 2020-07-14 19:04:26 AEST
What platform, compiler is this, and in particular what configure options and CFLAGS did you give?  I see at least one non-standard compiler flag.

A quick test with openssh-8.2p1 and openssl-1.1.1d here compiles OK:

$ CFLAGS="-g -O0 -D_FORTIFY_SOURCE=2 -DDEBUG_KEXECDH" ./configure --with-ssl-dir=/opt/openssl/1.1.1d && make clean && make
[...]
$ ./ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1d  10 Sep 2019

$ ./configure --with-ssl-dir=/opt/openssl/1.1.1d --with-cflags=-DDEBUG_KEXECDH && make clean && make
[...]
$./ssh -V 
OpenSSH_8.2p1, OpenSSL 1.1.1d  10 Sep 2019

(I also renamed my system openssl include dir, which didn't make a difference).  Is it possible it's picking up includes from a different version of OpenSSL somewhere in the search path?

> sshkey.c: In function ‘sshkey_parse_private_pem_fileblob’:
> sshkey.c:4625:27: error: dereferencing pointer to incomplete type
>  BIO_read(bio, keybuf, bio->num_write);

wait, OpenSSH 8.2p1 doesn't even contain that line of code.

$ curl -s https://raw.githubusercontent.com/openssh/openssh-portable/V_8_2/sshkey.c | grep num_write
$

what modifications have you made to the code?
Comment 4 cun 2020-07-16 16:02:35 AEST
yes

edit   openssl-compat.c
...
#include "internal/bio_lcl.h"
....
Comment 5 Darren Tucker 2020-07-16 17:32:07 AEST
(In reply to cun from comment #4)
> yes
> 
> edit   openssl-compat.c
> ...
> #include "internal/bio_lcl.h"
> ....

that can't be the only change since the line you're reporting errors on does not exist in the source code that the OpenSSH team ships.  AFAICT the code as shipped by us compiles just fine with OpenSSL 1.1.1d.
Comment 6 Darren Tucker 2020-07-16 17:40:39 AEST
(In reply to cun from comment #0)
> sshkey.c: In function ‘sshkey_parse_private_pem_fileblob’:
> sshkey.c:4625:27: error: dereferencing pointer to incomplete type
>   BIO_read(bio, keybuf, bio->num_write);

In the sshkey.c shipped with OpenSSH 8.2p1, sshkey_parse_private_pem_fileblob() runs from line 4503 to 4602 and the code block immediately before the error ends at line 4522.  This means you have added at least 100 lines of code to this file not including the one with the error.  If you change the code and it doesn't work that's something you need to fix yourself.
Comment 7 Damien Miller 2021-04-23 15:02:04 AEST
closing resolved bugs as of 8.6p1 release