X509_cmp_time (possible) bug

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

X509_cmp_time (possible) bug

Dmitry Belyavsky-3
Hello,

The X509_cmp_time function is documented as returning -1 or 1 on success and 0 on error.

In fact it returns result of strcmp:
int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) {
...
    i = strcmp(buff1, buff2);
    if (i == 0)                 /* wait a second then return younger */
        return -1;
    else
        return i;


According to documentation to the strcmp,

The strcmp() and strncmp() functions return an integer less than, equal to, or greater than  zero  if  s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. 

It means (and have been met in practice) that X509_cmp_time() returns other values than 1/-1.
So it seems reasonable to either update documentation or fix the behavior.

Thank you!

--
SY, Dmitry Belyavsky

--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Reply | Threaded
Open this post in threaded view
|

Re: X509_cmp_time (possible) bug

OpenSSL - Dev mailing list
Yes, it’s annoying, but it’s historic. I looked into changing this at one point.

I recommend using ASN1_TIME_cmp_time_t() (from the master branch) instead, for the results you are expecting.
--
-Todd Short
// "One if by land, two if by sea, three if by the Internet."

On Sep 9, 2017, at 10:10 AM, Dmitry Belyavsky <[hidden email]> wrote:

Hello,

The X509_cmp_time function is documented as returning -1 or 1 on success and 0 on error.

In fact it returns result of strcmp:
int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) {
...
    i = strcmp(buff1, buff2);
    if (i == 0)                 /* wait a second then return younger */
        return -1;
    else
        return i;


According to documentation to the strcmp,

The strcmp() and strncmp() functions return an integer less than, equal to, or greater than  zero  if  s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2. 

It means (and have been met in practice) that X509_cmp_time() returns other values than 1/-1.
So it seems reasonable to either update documentation or fix the behavior.

Thank you!

--
SY, Dmitry Belyavsky
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Reply | Threaded
Open this post in threaded view
|

Re: X509_cmp_time (possible) bug

Daniel Kahn Gillmor
On Mon 2017-09-11 14:16:11 +0000, Short, Todd via openssl-dev wrote:
> Yes, it’s annoying, but it’s historic. I looked into changing this at one point.

I think Dimitry's point was that the documentation doesn't match the
implementation because of the flexibility of strcmp's defined return
code.

However, i think commit 80770da39ebba0101079477611b7ce2f426653c5 ("X509
time: tighten validation per RFC 5280") resolves Dmitry's concerns.

        --dkg
--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev
Reply | Threaded
Open this post in threaded view
|

Re: X509_cmp_time (possible) bug

OpenSSL - Dev mailing list
Correct, 

But if one want’s strcmp()’s behavior (i.e. 0 is equality), ASN1_TIME_cmp_time_t() will work (and was written because X509_cmp_time() couldn’t be changed without breaking other things).
--
-Todd Short
// "One if by land, two if by sea, three if by the Internet."

On Sep 11, 2017, at 10:43 AM, Daniel Kahn Gillmor <[hidden email]> wrote:

On Mon 2017-09-11 14:16:11 +0000, Short, Todd via openssl-dev wrote:
Yes, it’s annoying, but it’s historic. I looked into changing this at one point.

I think Dimitry's point was that the documentation doesn't match the
implementation because of the flexibility of strcmp's defined return
code.

However, i think commit 80770da39ebba0101079477611b7ce2f426653c5 ("X509
time: tighten validation per RFC 5280") resolves Dmitry's concerns.

       --dkg


--
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev