TrustInSoft / tis-interpreter

An interpreter for finding subtle bugs in programs written in standard C
565 stars 28 forks source link

\pointer_comparable error message #96

Open kroeckx opened 8 years ago

kroeckx commented 8 years ago

I'm getting:

crypto/asn1/tasn_dec.c:191:[kernel] warning: pointer comparison: assert \pointer_comparable((void *)0, (void *)aux);
              stack: asn1_item_embed_d2i :: crypto/asn1/tasn_dec.c:162 <-
                     ASN1_item_ex_d2i :: crypto/asn1/tasn_dec.c:152 <-

The line in question is

if (aux && aux->asn1_cb)

I don't what it's trying to say, and I don't see anything obviously wrong.

pascal-cuoq commented 8 years ago

One of the issues here is that the warning message does not give enough information. Would it be possible to have the means to reproduce it (source code and commandline)?

kroeckx commented 8 years ago

I'm can reproduce it using the following test file:

#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/x509v3.h>

int main()
{
    const unsigned char *buf = "x";
    const unsigned char *p = buf;
    const ASN1_ITEM *item_type = ASN1_ITEM_rptr(X509);

    ASN1_VALUE *o = ASN1_item_d2i(NULL, &p, 1, item_type);
    ASN1_item_free(o, item_type);
    return 0;
}

And calling:

tis-interpreter.sh --cc "-I../include" asn1_test.c ../crypto/asn1/tasn_dec.c

Where tasn_dec.c is from the openssl source, and the -I points to the openssl source include directory.

I don't expect the whole program to work with just tasn_dec.c, but it should be enough to reproduce it.

pascal-cuoq commented 8 years ago

After pre-processing, the line const ASN1_ITEM *item_type = ASN1_ITEM_rptr(X509); in the function main is expansed into:

  ASN1_ITEM const *item_type;
  …
  item_type = & X509_it;

tis-interpreter's problem comes from having a declaration for the variable X509_it but no definition. It's not easy to grep for (I used: for i infind . -name *.o; do echo $i ; nm $i | grep D.*X509_it ; done) but it turns out to be defined by crypto/x509/x_x509.c.

Working through the next missing functions, and having commented out the use of atexit, I arrived to the following commandline:

tis-interpreter.sh --cc -I. --cc -Iinclude --cc -Icrypto/include test_asn1.c \
crypto/asn1/tasn_dec.c crypto/x509/x_x509.c crypto/asn1/asn1_lib.c \
crypto/err/err.c crypto/threads_none.c crypto/mem.c \
crypto/init.c crypto/cryptlib.c crypto/err/err_all.c crypto/lhash/lhash.c

Next tis-interpreter warns about the type of a function pointer and the type of the pointed function being different at the time of application. It's about this function, defined in crypto/err/err.c:

static unsigned long err_string_data_hash(const ERR_STRING_DATA *a)

And the type difference is that the hash member of OPENSSL_LHASH takes a const void* instead of a const ERR_STRING_DATA *.

It is possible to pass through this error in order to see what happens afterwards by adding -no-val-warn-harmless-function-pointers -val-stop-at-nth-alarm 100000 to the commandline:

tis-interpreter.sh --cc -I. --cc -Iinclude --cc -Icrypto/include test_asn1.c \
crypto/asn1/tasn_dec.c crypto/x509/x_x509.c crypto/asn1/asn1_lib.c \
crypto/err/err.c crypto/threads_none.c crypto/mem.c \
crypto/init.c crypto/cryptlib.c crypto/err/err_all.c crypto/lhash/lhash.c \
-no-val-warn-harmless-function-pointers -val-stop-at-nth-alarm 100000

I get:

crypto/err/err_all.c:50:[value] warning: Library function call. Stopping.
                 stack: ERR_load_BN_strings :: crypto/err/err_all.c:50 <- …

There is where I need to let you continue again.


Your report shows several issues:

kroeckx commented 8 years ago

I actually already have local changes for the atexit and the function pointer type mismatches, and I know which files are needed for all those ERRload*, so it's really the first of the issues you mentioned for me.

kroeckx commented 8 years ago

This seems to be error message seems to be related:

crypto/asn1/tasn_new.c:163:[value] warning: The following sub-expression cannot be evaluated:
             (int)it->itype == 0x4

             All sub-expressions with their values:
             int  (int)it->itype ∈ [-128..127]
             char  it->itype ∈ [-128..127]
             ASN1_ITEM const *  it ∈ {{ &ASN1_INTEGER_it }}
             int  0x4 ∈ {4}

             Stopping

In that case it was a missing tasn_typ.c file.