portable icon indicating copy to clipboard operation
portable copied to clipboard

*_it variables (ASN1_ITEM for builtin types) not accessible on Windows

Open rhenium opened this issue 6 years ago • 5 comments

(This issue was originally reported at https://bugs.ruby-lang.org/issues/13902)

When an application is compiled with cl.exe, it cannot access *_it variables properly (OCSP_BASICRESP_it in the example code below).

I can reproduce this with both libressl-2.2.9-windows.zip and libressl-2.5.5-windows.zip downloaded from https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/.

test.c:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/ocsp.h>
#include <openssl/asn1t.h>

int main(int argc, char **argv)
{
	OCSP_BASICRESP *bs;
	size_t i;
	int ret;

	puts("dump of OCSP_BASICRESP_it:");
	for (i = 0; i < sizeof(OCSP_BASICRESP_it); i++)
		printf("%02X", ((unsigned char *)&OCSP_BASICRESP_it)[i]);
	puts("");

	bs = OCSP_BASICRESP_new();
	if (!bs) {
		puts("bad alloc");
		return 1;
	}

	/*
	 * in crypto/ocsp/ocsp_asn.c:
	 *
	 * int
	 * i2d_OCSP_BASICRESP(OCSP_BASICRESP *a, unsigned char **out)
	 * {
	 * 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &OCSP_BASICRESP_it);
	 * }
	 */
	puts("trying i2d_OCSP_BASICRESP():");
	ret = i2d_OCSP_BASICRESP(bs, NULL);
	if (ret < 0)
		puts("ok i2d_(,NULL) error");
	else
		puts("ok");

	puts("trying ASN1_item_i2d():");
	ret = ASN1_item_i2d((ASN1_VALUE *)bs, NULL,
			    ASN1_ITEM_rptr(OCSP_BASICRESP));
	if (ret < 0)
		puts("ok ASN1_item_i2d(,NULL,) error");
	else
		puts("ok");
}
PS C:\mswin64\src\test> cl /Zi /I\mswin64\libressl-2.5.5-windows\include test.c C:\mswin64\libressl-2.5.5-windows\x64\libcrypto-41.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25507.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test.c
Warning, overriding WinCrypt defines
Microsoft (R) Incremental Linker Version 14.11.25507.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
/debug
test.obj
C:\mswin64\libressl-2.5.5-windows\x64\libcrypto-41.lib
PS C:\mswin64\src\test> .\test.exe
dump of OCSP_BASICRESP_it:
FF25BC5E070040534883EC20B901000000E858CBFFFFE86CADFFFF8BC8E871ABFFFFE85EB4FFFF488BD8E802B8FFFFB9
trying i2d_OCSP_BASICRESP():
ok
trying ASN1_item_i2d():
[ segfault in ASN1_item_ex_i2d() ]

I didn't dig further, but it looks like ASN1_item_i2d() is crashing because OCSP_BASICRESP_it points to garbage.

rhenium avatar Sep 15 '17 18:09 rhenium