Commit 4c9b0a03 authored by Gunnar Kudrjavets's avatar Gunnar Kudrjavets Committed by Matt Caswell
Browse files

Initialize potentially uninitialized local variables



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: default avatarMatt 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: default avatarRich Salz <rsalz@openssl.org>
parent 4407d070
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ int app_init(long mesgwin);
int chopup_args(ARGS *arg, char *buf)
{
    int quoted;
    char c, *p;
    char c = '\0', *p = NULL;

    arg->argc = 0;
    if (arg->size == 0) {
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ int dsaparam_main(int argc, char **argv)
    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;
+1 −1
Original line number Diff line number Diff line
@@ -631,7 +631,7 @@ static tlsextstatusctx tlscstatp = { NULL, NULL, NULL, 0, -1, 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;
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
    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;

+1 −1
Original line number Diff line number Diff line
@@ -645,7 +645,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
    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) {
Loading