diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2016-06-18 16:46:13 +0200 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2016-07-15 15:09:05 +0200 |
commit | d166ed8c11e10e9fdaeac182effb9dd318843924 (patch) | |
tree | fd47ffb1f5d42b121b04d14c1a8f6bdc659637f6 /test/mdc2test.c | |
parent | Windows: allow input and output flags to end with a space, or not (diff) | |
download | openssl-d166ed8c11e10e9fdaeac182effb9dd318843924.tar.xz openssl-d166ed8c11e10e9fdaeac182effb9dd318843924.zip |
check return values for EVP_Digest*() APIs
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'test/mdc2test.c')
-rw-r--r-- | test/mdc2test.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/test/mdc2test.c b/test/mdc2test.c index dc8dd58d78..d56bdcd878 100644 --- a/test/mdc2test.c +++ b/test/mdc2test.c @@ -43,7 +43,7 @@ static unsigned char pad2[16] = { int main(int argc, char *argv[]) { - int ret = 0; + int ret = 1; unsigned char md[MDC2_DIGEST_LENGTH]; int i; EVP_MD_CTX *c; @@ -54,9 +54,11 @@ int main(int argc, char *argv[]) # endif c = EVP_MD_CTX_new(); - EVP_DigestInit_ex(c, EVP_mdc2(), NULL); - EVP_DigestUpdate(c, (unsigned char *)text, strlen(text)); - EVP_DigestFinal_ex(c, &(md[0]), NULL); + if (c == NULL + || !EVP_DigestInit_ex(c, EVP_mdc2(), NULL) + || !EVP_DigestUpdate(c, (unsigned char *)text, strlen(text)) + || !EVP_DigestFinal_ex(c, &(md[0]), NULL)) + goto err; if (memcmp(md, pad1, MDC2_DIGEST_LENGTH) != 0) { for (i = 0; i < MDC2_DIGEST_LENGTH; i++) @@ -65,15 +67,18 @@ int main(int argc, char *argv[]) for (i = 0; i < MDC2_DIGEST_LENGTH; i++) printf("%02X", pad1[i]); printf(" <- correct\n"); - ret = 1; - } else + goto err; + } else { printf("pad1 - ok\n"); + } - EVP_DigestInit_ex(c, EVP_mdc2(), NULL); + if (!EVP_DigestInit_ex(c, EVP_mdc2(), NULL)) + goto err; /* FIXME: use a ctl function? */ ((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2; - EVP_DigestUpdate(c, (unsigned char *)text, strlen(text)); - EVP_DigestFinal_ex(c, &(md[0]), NULL); + if (!EVP_DigestUpdate(c, (unsigned char *)text, strlen(text)) + || !EVP_DigestFinal_ex(c, &(md[0]), NULL)) + goto err; if (memcmp(md, pad2, MDC2_DIGEST_LENGTH) != 0) { for (i = 0; i < MDC2_DIGEST_LENGTH; i++) @@ -82,10 +87,12 @@ int main(int argc, char *argv[]) for (i = 0; i < MDC2_DIGEST_LENGTH; i++) printf("%02X", pad2[i]); printf(" <- correct\n"); - ret = 1; - } else + } else { printf("pad2 - ok\n"); + ret = 0; + } + err: EVP_MD_CTX_free(c); EXIT(ret); } |