Skip to content

Commit

Permalink
Avoid overflow issues in X509_cmp.
Browse files Browse the repository at this point in the history
The length is a long, so returning the difference does not quite work.

Thanks to Torbjörn Granlund for noticing.

Reviewed-by: Rich Salz <[email protected]>
Reviewed-by: Richard Levitte <[email protected]>
  • Loading branch information
davidben authored and levitte committed Apr 29, 2016
1 parent a1f4128 commit 87a8405
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crypto/x509/x509_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ int X509_cmp(const X509 *a, const X509 *b)
return rv;
/* Check for match against stored encoding too */
if (!a->cert_info.enc.modified && !b->cert_info.enc.modified) {
rv = (int)(a->cert_info.enc.len - b->cert_info.enc.len);
if (rv)
return rv;
if (a->cert_info.enc.len < b->cert_info.enc.len)
return -1;
if (a->cert_info.enc.len > b->cert_info.enc.len)
return 1;
return memcmp(a->cert_info.enc.enc, b->cert_info.enc.enc,
a->cert_info.enc.len);
}
Expand Down

0 comments on commit 87a8405

Please sign in to comment.