Compiling OpenSSL code with MSVC and /W4 results in a number of warnings.
One category of warnings is particularly interesting - C4701 (potentially
uninitialized local variable 'name' used). This warning pretty much means
that there's a code path which results in uninitialized variables being used
or returned. Depending on compiler, its options, OS, values in registers
and/or stack, the results can be nondeterministic. Cases like this are very
hard to debug so it's rational to fix these issues.
This patch contains a set of trivial fixes for all the C4701 warnings (just
initializing variables to 0 or NULL or appropriate error code) to make sure
that deterministic values will be returned from all the execution paths.
RT#3835
Signed-off-by: Matt Caswell <matt@openssl.org>
Matt's note: All of these appear to be bogus warnings, i.e. there isn't
actually a code path where an unitialised variable could be used - its just
that the compiler hasn't been able to figure that out from the logic. So
this commit is just about silencing spurious warnings.
Reviewed-by: Rich Salz <rsalz@openssl.org>
int chopup_args(ARGS *arg, char *buf)
{
int quoted;
- char c, *p;
+ char c = '\0', *p = NULL;
arg->argc = 0;
if (arg->size == 0) {
DSA *dsa = NULL;
BIO *in = NULL, *out = NULL;
BN_GENCB *cb = NULL;
- int numbits = -1, num, genkey = 0, need_rand = 0, non_fips_allow = 0;
+ int numbits = -1, num = 0, genkey = 0, need_rand = 0, non_fips_allow = 0;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, noout = 0, C = 0, ret =
1;
int i, text = 0;
static int cert_status_cb(SSL *s, void *arg)
{
tlsextstatusctx *srctx = arg;
- char *host, *port, *path;
+ char *host = NULL, *port = NULL, *path = NULL;
int use_ssl;
unsigned char *rspder = NULL;
int rspderlen;
unsigned char *p;
const unsigned char *cp;
int cpy_len;
- long hdr_len;
+ long hdr_len = 0;
int hdr_constructed = 0, hdr_tag, hdr_class;
int r;
long plen;
char cst, inf, free_cont = 0;
const unsigned char *p;
- BUF_MEM buf;
+ BUF_MEM buf = { 0 };
const unsigned char *cont = NULL;
long len;
if (!pval) {
int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
size_t *siglen)
{
- int sctx, r = 0;
+ int sctx = 0, r = 0;
EVP_PKEY_CTX *pctx = ctx->pctx;
if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
if (!sigret)
sctx = 0;
if (sigret) {
unsigned char md[EVP_MAX_MD_SIZE];
- unsigned int mdlen;
+ unsigned int mdlen = 0;
if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
if (sctx)
r = ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx);
size_t siglen)
{
unsigned char md[EVP_MAX_MD_SIZE];
- int r;
- unsigned int mdlen;
- int vctx;
+ int r = 0;
+ unsigned int mdlen = 0;
+ int vctx = 0;
if (ctx->pctx->pmeth->verifyctx)
vctx = 1;
unsigned int *siglen, EVP_PKEY *pkey)
{
unsigned char m[EVP_MAX_MD_SIZE];
- unsigned int m_len;
- int i = 0, ok = 0, v;
+ unsigned int m_len = 0;
+ int i = 0, ok = 0, v = 0;
EVP_PKEY_CTX *pkctx = NULL;
*siglen = 0;
if (!EVP_DigestFinal_ex(ctx, m, &m_len))
goto err;
} else {
- int rv;
+ int rv = 0;
EVP_MD_CTX tmp_ctx;
EVP_MD_CTX_init(&tmp_ctx);
rv = EVP_MD_CTX_copy_ex(&tmp_ctx, ctx);
unsigned int siglen, EVP_PKEY *pkey)
{
unsigned char m[EVP_MAX_MD_SIZE];
- unsigned int m_len;
- int i = 0, ok = 0, v;
+ unsigned int m_len = 0;
+ int i = 0, ok = 0, v = 0;
EVP_PKEY_CTX *pkctx = NULL;
if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
if (!EVP_DigestFinal_ex(ctx, m, &m_len))
goto err;
} else {
- int rv;
+ int rv = 0;
EVP_MD_CTX tmp_ctx;
EVP_MD_CTX_init(&tmp_ctx);
rv = EVP_MD_CTX_copy_ex(&tmp_ctx, ctx);
int klen, pem_password_cb *callback, void *u)
{
EVP_CIPHER_CTX ctx;
- int dsize = 0, i, j, ret = 0;
+ int dsize = 0, i = 0, j = 0, ret = 0;
unsigned char *p, *data = NULL;
const char *objstr = NULL;
char buf[PEM_BUFSIZE];
static int check_revocation(X509_STORE_CTX *ctx)
{
- int i, last, ok;
+ int i = 0, last = 0, ok = 0;
if (!(ctx->param->flags & X509_V_FLAG_CRL_CHECK))
return 1;
if (ctx->param->flags & X509_V_FLAG_CRL_CHECK_ALL)
static int check_cert(X509_STORE_CTX *ctx)
{
X509_CRL *crl = NULL, *dcrl = NULL;
- X509 *x;
- int ok, cnum;
- unsigned int last_reasons;
+ X509 *x = NULL;
+ int ok = 0, cnum = 0;
+ unsigned int last_reasons = 0;
cnum = ctx->error_depth;
x = sk_X509_value(ctx->chain, cnum);
ctx->current_cert = x;
CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN];
unsigned afi, *safi = NULL, safi_;
- const char *addr_chars;
+ const char *addr_chars = NULL;
int prefixlen, i1, i2, delim, length;
if (!name_cmp(val->name, "IPv4")) {
for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
- int i1, i2, i3, is_range, which;
+ int i1 = 0, i2 = 0, i3 = 0, is_range = 0, which = 0;
/*
* Figure out whether this is an AS or an RDI.
X509V3_CTX *ctx)
{
unsigned char *ext_der = NULL;
- long ext_len;
+ long ext_len = 0;
ASN1_OBJECT *obj = NULL;
ASN1_OCTET_STRING *oct = NULL;
X509_EXTENSION *extension = NULL;
int ssl_check_clienthello_tlsext_late(SSL *s)
{
int ret = SSL_TLSEXT_ERR_OK;
- int al;
+ int al = SSL_AD_INTERNAL_ERROR;
/*
* If status request then ask callback what to do. Note: this must be
static int process_test(struct evp_test *t, char *buf, int verbose)
{
- char *keyword, *value;
+ char *keyword = NULL, *value = NULL;
int rv = 0, add_key = 0;
- long save_pos;
- struct key_list **lst, *key;
+ long save_pos = 0;
+ struct key_list **lst = NULL, *key = NULL;
EVP_PKEY *pk = NULL;
- const struct evp_test_method *tmeth;
+ const struct evp_test_method *tmeth = NULL;
if (verbose)
fputs(buf, stdout);
if (!parse_line(&keyword, &value, buf))