arg->argc = 0;
if (arg->size == 0) {
arg->size = 20;
- arg->argv = OPENSSL_malloc(sizeof(char *) * arg->size);
+ arg->argv = app_malloc(sizeof(char *) * arg->size, "argv space");
if (arg->argv == NULL)
return 0;
}
ok = UI_add_input_string(ui, prompt, ui_flags, buf,
PW_MIN_LENGTH, bufsiz - 1);
if (ok >= 0 && verify) {
- buff = OPENSSL_malloc(bufsiz);
- if (!buff) {
- BIO_printf(bio_err, "Out of memory\n");
- UI_free(ui);
- OPENSSL_free(prompt);
- return 0;
- }
+ buff = app_malloc(bufsiz, "password buffer");
ok = UI_add_verify_string(ui, prompt, ui_flags, buff,
PW_MIN_LENGTH, bufsiz - 1, buf);
}
}
while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0));
- if (buff) {
- OPENSSL_cleanse(buff, (unsigned int)bufsiz);
- OPENSSL_free(buff);
- }
+ OPENSSL_clear_free(buff, (unsigned int)bufsiz);
if (ok >= 0)
res = strlen(buf);
}
err:
- if (host)
- OPENSSL_free(host);
- if (path)
- OPENSSL_free(path);
- if (port)
- OPENSSL_free(port);
+ OPENSSL_free(host);
+ OPENSSL_free(path);
+ OPENSSL_free(port);
if (bio)
BIO_free_all(bio);
- if (rctx)
- OCSP_REQ_CTX_free(rctx);
+ OCSP_REQ_CTX_free(rctx);
if (rv != 1) {
BIO_printf(bio_err, "Error loading %s from %s\n",
pcert ? "certificate" : "CRL", url);
BIO_printf(bio_err, "unable to load certificate\n");
ERR_print_errors(bio_err);
}
- if (cert != NULL)
- BIO_free(cert);
+ BIO_free(cert);
return (x);
}
goto end;
}
end:
- if (key != NULL)
- BIO_free(key);
+ BIO_free(key);
if (pkey == NULL) {
BIO_printf(bio_err, "unable to load %s\n", key_descrip);
ERR_print_errors(bio_err);
pkey = b2i_PublicKey_bio(key);
#endif
end:
- if (key != NULL)
- BIO_free(key);
+ BIO_free(key);
if (pkey == NULL)
BIO_printf(bio_err, "unable to load %s\n", key_descrip);
return (pkey);
end:
- if (xis)
- sk_X509_INFO_pop_free(xis, X509_INFO_free);
+ sk_X509_INFO_pop_free(xis, X509_INFO_free);
if (rv == 0) {
if (pcerts) {
return rv;
}
+void* app_malloc(int sz, const char *what)
+{
+ void *vp = OPENSSL_malloc(sz);
+
+ if (vp == NULL) {
+ BIO_printf(bio_err, "%s: Could not allocate %d bytes for %s\n",
+ opt_getprog(), sz, what);
+ ERR_print_errors(bio_err);
+ exit(1);
+ }
+ return vp;
+}
+
+
+
STACK_OF(X509) *load_certs(const char *file, int format,
const char *pass, ENGINE *e, const char *desc)
{
}
err:
BIO_free(in);
- if (ai != NULL)
- ASN1_INTEGER_free(ai);
+ ASN1_INTEGER_free(ai);
return (ret);
}
}
err:
BIO_free_all(out);
- if (ai != NULL)
- ASN1_INTEGER_free(ai);
+ ASN1_INTEGER_free(ai);
return (ret);
}
{
BIGNUM *btmp;
int ret = 0;
+
if (b)
btmp = b;
else
error:
- if (!b)
+ if (btmp != b)
BN_free(btmp);
return ret;
}
}
- if ((retdb = OPENSSL_malloc(sizeof(CA_DB))) == NULL) {
- fprintf(stderr, "Out of memory\n");
- goto err;
- }
-
+ retdb = app_malloc(sizeof *retdb, "new DB");
retdb->db = tmpdb;
tmpdb = NULL;
if (db_attr)
}
err:
- if (dbattr_conf)
- NCONF_free(dbattr_conf);
- if (tmpdb)
- TXT_DB_free(tmpdb);
+ NCONF_free(dbattr_conf);
+ TXT_DB_free(tmpdb);
BIO_free_all(in);
return retdb;
}
void free_index(CA_DB *db)
{
if (db) {
- if (db->db)
- TXT_DB_free(db->db);
+ TXT_DB_free(db->db);
OPENSSL_free(db);
}
}
n = X509_NAME_new();
if (n == NULL)
return NULL;
- work = strdup(cp);
+ work = OPENSSL_strdup(cp);
if (work == NULL)
goto err;
goto err;
}
- free(work);
+ OPENSSL_free(work);
return n;
err:
X509_NAME_free(n);
- free(work);
+ OPENSSL_free(work);
return NULL;
}
BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
- if (psk_key)
- OPENSSL_free(psk_key);
-
+ OPENSSL_free(psk_key);
psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
BIO_pop(bconn);
BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
- if (psk_key)
- OPENSSL_free(psk_key);
-
+ OPENSSL_free(psk_key);
psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
BIO_pop(bconn);
if (len >= 65535)
return NULL;
- out = OPENSSL_malloc(strlen(in) + 1);
- if (!out)
- return NULL;
-
+ out = app_malloc(strlen(in) + 1, "NPN buffer");
for (i = 0; i <= len; ++i) {
if (i == len || in[i] == ',') {
if (i - start > 255) {
# if defined(UNICODE) || defined(_UNICODE)
size_t i, len_0 = strlen(name) + 1;
- if (len_0 > sizeof(FileData.cFileName) / sizeof(FileData.cFileName[0]))
+ if (len_0 > OSSL_NELEM(FileData.cFileName))
return -1;
# if !defined(_WIN32_WCE) || _WIN32_WCE>=101