diff options
author | slontis <shane.lontis@oracle.com> | 2023-03-20 14:48:33 +1000 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2023-04-24 14:39:19 +0200 |
commit | 09ff84bd2752cac649f57cfbf95b49dbce1c69ee (patch) | |
tree | 9a3dbf4aa9835f2be7d874cde743f6dfa1de6293 /demos | |
parent | a80840c663e3409203b0235764e53d8624f74cb8 (diff) |
Fixup demo exit status magic numbers
The demo code is quite often block copied for new demos,
so this PR changes demos to use EXIT_SUCCESS & EXIT_FAILURE
instead of using 0 and 1.
Internal functions use the normal notation of 0 = error, 1 = success,
but the value returned by main() must use EXIT_SUCCESS and EXIT_FAILURE.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20545)
Diffstat (limited to 'demos')
47 files changed, 238 insertions, 249 deletions
diff --git a/demos/bio/client-arg.c b/demos/bio/client-arg.c index 202afa1ee8..c96e6eb08c 100644 --- a/demos/bio/client-arg.c +++ b/demos/bio/client-arg.c @@ -22,6 +22,7 @@ int main(int argc, char **argv) char **args = argv + 1; const char *connect_str = "localhost:4433"; int nargs = argc - 1; + int ret = EXIT_FAILURE; ctx = SSL_CTX_new(TLS_client_method()); cctx = SSL_CONF_CTX_new(); @@ -100,9 +101,10 @@ int main(int argc, char **argv) break; BIO_write(out, tmpbuf, len); } + ret = EXIT_SUCCESS; end: SSL_CONF_CTX_free(cctx); BIO_free_all(sbio); BIO_free(out); - return 0; + return ret; } diff --git a/demos/bio/client-conf.c b/demos/bio/client-conf.c index 916876bfab..b8bb6819b9 100644 --- a/demos/bio/client-conf.c +++ b/demos/bio/client-conf.c @@ -25,6 +25,7 @@ int main(int argc, char **argv) CONF_VALUE *cnf; const char *connect_str = "localhost:4433"; long errline = -1; + int ret = EXIT_FAILURE; conf = NCONF_new(NULL); @@ -108,10 +109,12 @@ int main(int argc, char **argv) break; BIO_write(out, tmpbuf, len); } + ret = EXIT_SUCCESS; + end: SSL_CONF_CTX_free(cctx); BIO_free_all(sbio); BIO_free(out); NCONF_free(conf); - return 0; + return ret; } diff --git a/demos/cipher/aesccm.c b/demos/cipher/aesccm.c index 5a2d428150..b70209be86 100644 --- a/demos/cipher/aesccm.c +++ b/demos/cipher/aesccm.c @@ -229,10 +229,10 @@ err: int main(int argc, char **argv) { if (!aes_ccm_encrypt()) - return 1; + return EXIT_FAILURE; if (!aes_ccm_decrypt()) - return 1; + return EXIT_FAILURE; - return 0; + return EXIT_SUCCESS; } diff --git a/demos/cipher/aesgcm.c b/demos/cipher/aesgcm.c index aaf4000d57..0e4cf7122d 100644 --- a/demos/cipher/aesgcm.c +++ b/demos/cipher/aesgcm.c @@ -219,10 +219,10 @@ err: int main(int argc, char **argv) { if (!aes_gcm_encrypt()) - return 1; + return EXIT_FAILURE; if (!aes_gcm_decrypt()) - return 1; + return EXIT_FAILURE; - return 0; + return EXIT_SUCCESS; } diff --git a/demos/cipher/aeskeywrap.c b/demos/cipher/aeskeywrap.c index f987772e4f..3909fd473c 100644 --- a/demos/cipher/aeskeywrap.c +++ b/demos/cipher/aeskeywrap.c @@ -171,11 +171,10 @@ err: int main(int argc, char **argv) { if (!aes_wrap_encrypt()) - return 1; + return EXIT_FAILURE; if (!aes_wrap_decrypt()) - return 1; + return EXIT_FAILURE; - return 0; + return EXIT_SUCCESS; } - diff --git a/demos/cipher/ariacbc.c b/demos/cipher/ariacbc.c index 8999fe6e70..8542e4673e 100644 --- a/demos/cipher/ariacbc.c +++ b/demos/cipher/ariacbc.c @@ -169,10 +169,10 @@ err: int main(int argc, char **argv) { if (!aria_cbc_encrypt()) - return 1; + return EXIT_FAILURE; if (!aria_cbc_decrypt()) - return 1; + return EXIT_FAILURE; - return 0; + return EXIT_SUCCESS; } diff --git a/demos/cms/cms_comp.c b/demos/cms/cms_comp.c index ee1b5a38ce..3ccbfdddda 100644 --- a/demos/cms/cms_comp.c +++ b/demos/cms/cms_comp.c @@ -16,7 +16,7 @@ int main(int argc, char **argv) { BIO *in = NULL, *out = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; /* * On OpenSSL 1.0.0+ only: @@ -48,11 +48,11 @@ int main(int argc, char **argv) if (!SMIME_write_CMS(out, cms, in, flags)) goto err; - ret = 0; + ret = EXIT_SUCCESS; err: - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Compressing Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_ddec.c b/demos/cms/cms_ddec.c index cb6c2694c6..285eba91df 100644 --- a/demos/cms/cms_ddec.c +++ b/demos/cms/cms_ddec.c @@ -21,7 +21,7 @@ int main(int argc, char **argv) X509 *rcert = NULL; EVP_PKEY *rkey = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); @@ -68,11 +68,11 @@ int main(int argc, char **argv) if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0)) goto err; - ret = 0; + ret = EXIT_SUCCESS; err: - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Decrypting Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_dec.c b/demos/cms/cms_dec.c index f33ef1eb78..436f0088d2 100644 --- a/demos/cms/cms_dec.c +++ b/demos/cms/cms_dec.c @@ -18,7 +18,7 @@ int main(int argc, char **argv) X509 *rcert = NULL; EVP_PKEY *rkey = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); @@ -59,11 +59,10 @@ int main(int argc, char **argv) if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0)) goto err; - ret = 0; + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Decrypting Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_denc.c b/demos/cms/cms_denc.c index 4a2219dee3..4fbd72aae5 100644 --- a/demos/cms/cms_denc.c +++ b/demos/cms/cms_denc.c @@ -21,7 +21,7 @@ int main(int argc, char **argv) X509 *rcert = NULL; STACK_OF(X509) *recips = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; int flags = CMS_STREAM | CMS_DETACHED; @@ -77,11 +77,9 @@ int main(int argc, char **argv) if (!PEM_write_bio_CMS(out, cms)) goto err; - ret = 0; - + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Encrypting Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_enc.c b/demos/cms/cms_enc.c index ff5632a714..3af321521c 100644 --- a/demos/cms/cms_enc.c +++ b/demos/cms/cms_enc.c @@ -18,7 +18,7 @@ int main(int argc, char **argv) X509 *rcert = NULL; STACK_OF(X509) *recips = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; /* * On OpenSSL 1.0.0 and later only: @@ -73,11 +73,9 @@ int main(int argc, char **argv) if (!SMIME_write_CMS(out, cms, in, flags)) goto err; - ret = 0; - + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Encrypting Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_sign.c b/demos/cms/cms_sign.c index a52f5cec0f..8abc561941 100644 --- a/demos/cms/cms_sign.c +++ b/demos/cms/cms_sign.c @@ -18,7 +18,7 @@ int main(int argc, char **argv) X509 *scert = NULL; EVP_PKEY *skey = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; /* * For simple S/MIME signing use CMS_DETACHED. On OpenSSL 1.0.0 only: for @@ -69,11 +69,9 @@ int main(int argc, char **argv) if (!SMIME_write_CMS(out, cms, in, flags)) goto err; - ret = 0; - + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Signing Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_sign2.c b/demos/cms/cms_sign2.c index beda9779a3..72c7862593 100644 --- a/demos/cms/cms_sign2.c +++ b/demos/cms/cms_sign2.c @@ -18,7 +18,7 @@ int main(int argc, char **argv) X509 *scert = NULL, *scert2 = NULL; EVP_PKEY *skey = NULL, *skey2 = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); @@ -77,11 +77,9 @@ int main(int argc, char **argv) if (!SMIME_write_CMS(out, cms, in, CMS_STREAM)) goto err; - ret = 0; - + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Signing Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_uncomp.c b/demos/cms/cms_uncomp.c index 35e68ebcc6..02106197b4 100644 --- a/demos/cms/cms_uncomp.c +++ b/demos/cms/cms_uncomp.c @@ -16,7 +16,7 @@ int main(int argc, char **argv) { BIO *in = NULL, *out = NULL; CMS_ContentInfo *cms = NULL; - int ret = 1; + int ret = EXIT_FAILURE; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); @@ -42,11 +42,9 @@ int main(int argc, char **argv) if (!CMS_uncompress(cms, out, NULL, 0)) goto err; - ret = 0; - + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Uncompressing Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/cms/cms_ver.c b/demos/cms/cms_ver.c index 3c0a7aa19e..0b6c469bf4 100644 --- a/demos/cms/cms_ver.c +++ b/demos/cms/cms_ver.c @@ -18,8 +18,7 @@ int main(int argc, char **argv) X509_STORE *st = NULL; X509 *cacert = NULL; CMS_ContentInfo *cms = NULL; - - int ret = 1; + int ret = EXIT_FAILURE; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); @@ -69,11 +68,9 @@ int main(int argc, char **argv) fprintf(stderr, "Verification Successful\n"); - ret = 0; - + ret = EXIT_SUCCESS; err: - - if (ret) { + if (ret != EXIT_SUCCESS) { fprintf(stderr, "Error Verifying Data\n"); ERR_print_errors_fp(stderr); } diff --git a/demos/digest/BIO_f_md.c b/demos/digest/BIO_f_md.c index 0a1f319f11..1317e82237 100644 --- a/demos/digest/BIO_f_md.c +++ b/demos/digest/BIO_f_md.c @@ -36,15 +36,14 @@ int main(int argc, char * argv[]) { - int result = 1; + int ret = EXIT_FAILURE; OSSL_LIB_CTX *library_context = NULL; BIO *input = NULL; - BIO *bio_digest = NULL; + BIO *bio_digest = NULL, *reading = NULL; EVP_MD *md = NULL; unsigned char buffer[512]; - size_t readct, writect; size_t digest_size; - char *digest_value=NULL; + char *digest_value = NULL; int j; input = BIO_new_fd(fileno(stdin), 1); @@ -89,7 +88,7 @@ int main(int argc, char * argv[]) * We will use BIO chaining so that as we read, the digest gets updated * See the man page for BIO_push */ - BIO *reading = BIO_push(bio_digest, input); + reading = BIO_push(bio_digest, input); while (BIO_read(reading, buffer, sizeof(buffer)) > 0) ; @@ -106,10 +105,10 @@ int main(int argc, char * argv[]) fprintf(stdout, "%02x", (unsigned char)digest_value[j]); } fprintf(stdout, "\n"); - result = 0; + ret = EXIT_SUCCESS; cleanup: - if (result != 0) + if (ret != EXIT_SUCCESS) ERR_print_errors_fp(stderr); OPENSSL_free(digest_value); @@ -118,5 +117,5 @@ cleanup: EVP_MD_free(md); OSSL_LIB_CTX_free(library_context); - return result; + return ret; } diff --git a/demos/digest/EVP_MD_demo.c b/demos/digest/EVP_MD_demo.c index e406801aff..51a87559d2 100644 --- a/demos/digest/EVP_MD_demo.c +++ b/demos/digest/EVP_MD_demo.c @@ -79,7 +79,7 @@ const unsigned char known_answer[] = { int demonstrate_digest(void) { OSSL_LIB_CTX *library_context; - int result = 0; + int ret = 0; const char *option_properties = NULL; EVP_MD *message_digest = NULL; EVP_MD_CTX *digest_context = NULL; @@ -161,12 +161,11 @@ int demonstrate_digest(void) fprintf(stdout, "\nDigest does not match known answer\n"); } else { fprintf(stdout, "Digest computed properly.\n"); - result = 1; + ret = 1; } - cleanup: - if (result != 1) + if (ret != 1) ERR_print_errors_fp(stderr); /* OpenSSL free functions will ignore NULL arguments */ EVP_MD_CTX_free(digest_context); @@ -174,10 +173,10 @@ cleanup: EVP_MD_free(message_digest); OSSL_LIB_CTX_free(library_context); - return result; + return ret; } int main(void) { - return demonstrate_digest() == 0; + return demonstrate_digest() ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/demos/digest/EVP_MD_stdin.c b/demos/digest/EVP_MD_stdin.c index 43a820f945..6990b721c5 100644 --- a/demos/digest/EVP_MD_stdin.c +++ b/demos/digest/EVP_MD_stdin.c @@ -34,7 +34,7 @@ int demonstrate_digest(BIO *input) { OSSL_LIB_CTX *library_context = NULL; - int result = 0; + int ret = 0; const char * option_properties = NULL; EVP_MD *message_digest = NULL; EVP_MD_CTX *digest_context = NULL; @@ -103,14 +103,14 @@ int demonstrate_digest(BIO *input) fprintf(stderr, "EVP_DigestFinal() failed.\n"); goto cleanup; } - result = 1; + ret = 1; for (ii=0; ii<digest_length; ii++) { fprintf(stdout, "%02x", digest_value[ii]); } fprintf(stdout, "\n"); cleanup: - if (result != 1) + if (ret != 1) ERR_print_errors_fp(stderr); /* OpenSSL free functions will ignore NULL arguments */ EVP_MD_CTX_free(digest_context); @@ -118,17 +118,19 @@ cleanup: EVP_MD_free(message_digest); OSSL_LIB_CTX_free(library_context); - return result; + return ret; } int main(void) { - int result = 1; + int ret = EXIT_FAILURE; BIO *input = BIO_new_fd(fileno(stdin), 1); if (input != NULL) { - result = demonstrate_digest(input); + ret = (demonstrate_digest(input) ? EXIT_SUCCESS : EXIT_FAILURE); BIO_free(input); } - return result; + if (ret != EXIT_SUCCESS) + ERR_print_errors_fp(stderr); + return ret; } diff --git a/demos/digest/EVP_MD_xof.c b/demos/digest/EVP_MD_xof.c index f31c047164..c2bd1a9fc5 100644 --- a/demos/digest/EVP_MD_xof.c +++ b/demos/digest/EVP_MD_xof.c @@ -43,7 +43,7 @@ static const char *propq = NULL; int main(int argc, char **argv) { - int rv = 1; + int ret = EXIT_FAILURE; OSSL_LIB_CTX *libctx = NULL; EVP_MD *md = NULL; EVP_MD_CTX *ctx = NULL; @@ -122,11 +122,11 @@ int main(int argc, char **argv) } } - rv = 0; + ret = EXIT_SUCCESS; end: OPENSSL_free(digest); EVP_MD_CTX_free(ctx); EVP_MD_free(md); OSSL_LIB_CTX_free(libctx); - return rv; + return ret; } diff --git a/demos/encode/ec_encode.c b/demos/encode/ec_encode.c index 8c296fbad8..a5fe2213df 100644 --- a/demos/encode/ec_encode.c +++ b/demos/encode/ec_encode.c @@ -28,7 +28,7 @@ static const char *propq = NULL; */ static EVP_PKEY *load_key(OSSL_LIB_CTX *libctx, FILE *f, const char *passphrase) { - int rv = 0; + int ret = 0; EVP_PKEY *pkey = NULL; OSSL_DECODER_CTX *dctx = NULL; int selection = 0; @@ -75,7 +75,7 @@ static EVP_PKEY *load_key(OSSL_LIB_CTX *libctx, FILE *f, const char *passphrase) goto cleanup; } - rv = 1; + ret = 1; cleanup: OSSL_DECODER_CTX_free(dctx); @@ -84,7 +84,7 @@ cleanup: * might fail subsequently, so ensure it's properly freed * in this case. */ - if (rv == 0) { + if (ret == 0) { EVP_PKEY_free(pkey); pkey = NULL; } @@ -100,7 +100,7 @@ cleanup: */ static int store_key(EVP_PKEY *pkey, FILE *f, const char *passphrase) { - int rv = 0; + int ret = 0; int selection; OSSL_ENCODER_CTX *ectx = NULL; @@ -165,15 +165,15 @@ static int store_key(EVP_PKEY *pkey, FILE *f, const char *passphrase) goto cleanup; } - rv = 1; + ret = 1; cleanup: OSSL_ENCODER_CTX_free(ectx); - return rv; + return ret; } int main(int argc, char **argv) { - int rv = 1; + int ret = EXIT_FAILURE; OSSL_LIB_CTX *libctx = NULL; EVP_PKEY *pkey = NULL; const char *passphrase_in = NULL, *passphrase_out = NULL; @@ -197,9 +197,9 @@ int main(int argc, char **argv) goto cleanup; } - rv = 0; + ret = EXIT_SUCCESS; cleanup: EVP_PKEY_free(pkey); OSSL_LIB_CTX_free(libctx); - return rv; + return ret; } diff --git a/demos/encode/rsa_encode.c b/demos/encode/rsa_encode.c index 2bf6d13e6f..fd06b970db 100644 --- a/demos/encode/rsa_encode.c +++ b/demos/encode/rsa_encode.c @@ -28,7 +28,7 @@ static const char *propq = NULL; */ static EVP_PKEY *load_key(OSSL_LIB_CTX *libctx, FILE *f, const char *passphrase) { - int rv = 0; + int ret = 0; EVP_PKEY *pkey = NULL; OSSL_DECODER_CTX *dctx = NULL; int selection = 0; @@ -75,7 +75,7 @@ static EVP_PKEY *load_key(OSSL_LIB_CTX *libctx, FILE *f, const char *passphrase) goto cleanup; } - rv = 1; + ret = 1; cleanup: OSSL_DECODER_CTX_free(dctx); @@ -84,7 +84,7 @@ cleanup: * might fail subsequently, so ensure it's properly freed * in this case. */ - if (rv == 0) { + if (ret == 0) { EVP_PKEY_free(pkey); pkey = NULL; } @@ -100,7 +100,7 @@ cleanup: */ static int store_key(EVP_PKEY *pkey, FILE *f, const char *passphrase) { - int rv = 0; + int ret = 0; int selection; OSSL_ENCODER_CTX *ectx = NULL; @@ -162,15 +162,15 @@ static int store_key(EVP_PKEY *pkey, FILE *f, const char *passphrase) goto cleanup; } - rv = 1; + ret = 1; cleanup: OSSL_ENCODER_CTX_free(ectx); - return rv; + return ret; } int main(int argc, char **argv) { - int rv = 1; + int ret = EXIT_FAILURE; OSSL_LIB_CTX *libctx = NULL; EVP_PKEY *pkey = NULL; const char *passphrase_in = NULL, *passphrase_out = NULL; @@ -194,9 +194,9 @@ int main(int argc, char **argv) goto cleanup; } - rv = 0; + ret = EXIT_SUCCESS; cleanup: EVP_PKEY_free(pkey); OSSL_LIB_CTX_free(libctx); - return rv; + return ret; } diff --git a/demos/kdf/hkdf.c b/demos/kdf/hkdf.c index cb7a170e94..52f505cfa3 100644 --- a/demos/kdf/hkdf.c +++ b/demos/kdf/hkdf.c @@ -43,7 +43,7 @@ static unsigned char hkdf_okm[] = { int main(int argc, char **argv) { - int rv = 1; + int ret = EXIT_FAILURE; EVP_KDF *kdf = NULL; EVP_KDF_CTX *kctx = NULL; unsigned char out[42]; @@ -95,10 |