On Mon, 2016-10-24 at 14:28 +0200, Andreas Schneider wrote:
> Hello,
> 
> asn1_read_value_type() with len = 0 passed fails for CHOICE and BIT
> STRINGĀ 
> types.
> See the attached patch which adds a testcase!

This function is documented to return "%ASN1_MEM_ERROR if The value
vector isn't big enough to store the result, and in this case @len will
contain the number of bytes needed.". That seems to be the case in your
example (even though the output is NULL, ASN1_MEM_ERROR is still
returned). Note that it can also return %ASN1_SUCCESS when provided
with NULL value and zero length, if the actual data are zero.

The attached patch should fix your test case.

regards,
Nikos
diff --git a/tests/spc_pe_image_data.c b/tests/spc_pe_image_data.c
index e014a8c..4e54d4a 100644
--- a/tests/spc_pe_image_data.c
+++ b/tests/spc_pe_image_data.c
@@ -62,7 +62,7 @@ int main (int argc, char** argv)
                                      NULL,
                                      &len,
                                      &etype);
-       if (result != ASN1_SUCCESS) {
+       if (result != ASN1_MEM_ERROR) {
                fprintf(stderr, "error in %d: %s\n", __LINE__, 
errorDescription);
                exit(1);
        }
@@ -84,7 +84,7 @@ int main (int argc, char** argv)
        etype = 0;
        len = 0;
        result = asn1_read_value_type(node1, "link", NULL, &len, &etype);
-       if (result != ASN1_SUCCESS)
+       if (result != ASN1_MEM_ERROR)
        {
                fprintf(stderr,
                        "error in %d: result is: %s\n",

Reply via email to