Skip to content

Commit

Permalink
fixup! fixup! fixup! Fixes a couple of memory leaks from missing chec…
Browse files Browse the repository at this point in the history
…ks of return value from sk_OPENSSL_STRING_push()
  • Loading branch information
fwh-dc committed Jan 1, 2025
1 parent 8e8fe42 commit 36bee2e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/asn1parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int asn1parse_main(int argc, char **argv)
dump = strtol(opt_arg(), NULL, 0);
break;
case OPT_STRPARSE:
if (!sk_OPENSSL_STRING_push(osk, opt_arg()))
if (sk_OPENSSL_STRING_push(osk, opt_arg()) <= 0)
goto end;
break;
case OPT_GENSTR:
Expand Down
18 changes: 9 additions & 9 deletions apps/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,14 @@ int cms_main(int argc, char **argv)
if (rr_from == NULL
&& (rr_from = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(rr_from, opt_arg()))
if (sk_OPENSSL_STRING_push(rr_from, opt_arg()) <= 0)
goto end;
break;
case OPT_RR_TO:
if (rr_to == NULL
&& (rr_to = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(rr_to, opt_arg()))
if (sk_OPENSSL_STRING_push(rr_to, opt_arg()) <= 0)
goto end;
break;
case OPT_PRINT:
Expand Down Expand Up @@ -590,14 +590,14 @@ int cms_main(int argc, char **argv)
if (sksigners == NULL
&& (sksigners = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(sksigners, signerfile))
if (sk_OPENSSL_STRING_push(sksigners, signerfile) <= 0)
goto end;
if (keyfile == NULL)
keyfile = signerfile;
if (skkeys == NULL
&& (skkeys = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(skkeys, keyfile))
if (sk_OPENSSL_STRING_push(skkeys, keyfile) <= 0)
goto end;
keyfile = NULL;
}
Expand All @@ -616,13 +616,13 @@ int cms_main(int argc, char **argv)
if (sksigners == NULL
&& (sksigners = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(sksigners, signerfile))
if (sk_OPENSSL_STRING_push(sksigners, signerfile) <= 0)
goto end;
signerfile = NULL;
if (skkeys == NULL
&& (skkeys = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(skkeys, keyfile))
if (sk_OPENSSL_STRING_push(skkeys, keyfile) <= 0)
goto end;
}
keyfile = opt_arg();
Expand Down Expand Up @@ -677,7 +677,7 @@ int cms_main(int argc, char **argv)
key_param->next = nparam;
key_param = nparam;
}
if (!sk_OPENSSL_STRING_push(key_param->param, opt_arg()))
if (sk_OPENSSL_STRING_push(key_param->param, opt_arg()) <= 0)
goto end;
break;
case OPT_V_CASES:
Expand Down Expand Up @@ -765,13 +765,13 @@ int cms_main(int argc, char **argv)
if (sksigners == NULL
&& (sksigners = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(sksigners, signerfile))
if (sk_OPENSSL_STRING_push(sksigners, signerfile) <= 0)
goto end;
if (skkeys == NULL && (skkeys = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (keyfile == NULL)
keyfile = signerfile;
if (!sk_OPENSSL_STRING_push(skkeys, keyfile))
if (sk_OPENSSL_STRING_push(skkeys, keyfile) <= 0)
goto end;
}
if (sksigners == NULL) {
Expand Down
4 changes: 2 additions & 2 deletions apps/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ int engine_main(int argc, char **argv)
test_avail++;
break;
case OPT_PRE:
if (!sk_OPENSSL_STRING_push(pre_cmds, opt_arg()))
if (sk_OPENSSL_STRING_push(pre_cmds, opt_arg()) <= 0)
goto end;
break;
case OPT_POST:
if (!sk_OPENSSL_STRING_push(post_cmds, opt_arg()))
if (sk_OPENSSL_STRING_push(post_cmds, opt_arg()) <= 0)
goto end;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ int pkcs12_main(int argc, char **argv)
if (canames == NULL
&& (canames = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(canames, opt_arg()))
if (sk_OPENSSL_STRING_push(canames, opt_arg()) <= 0)
goto end;
break;
case OPT_IN:
Expand Down
12 changes: 6 additions & 6 deletions apps/smime.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,14 @@ int smime_main(int argc, char **argv)
if (sksigners == NULL
&& (sksigners = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(sksigners, signerfile))
if (sk_OPENSSL_STRING_push(sksigners, signerfile) <= 0)
goto end;
if (keyfile == NULL)
keyfile = signerfile;
if (skkeys == NULL
&& (skkeys = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(skkeys, keyfile))
if (sk_OPENSSL_STRING_push(skkeys, keyfile) <= 0)
goto end;
keyfile = NULL;
}
Expand All @@ -348,13 +348,13 @@ int smime_main(int argc, char **argv)
if (sksigners == NULL
&& (sksigners = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(sksigners, signerfile))
if (sk_OPENSSL_STRING_push(sksigners, signerfile) <= 0)
goto end;
signerfile = NULL;
if (skkeys == NULL
&& (skkeys = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(skkeys, keyfile))
if (sk_OPENSSL_STRING_push(skkeys, keyfile) <= 0)
goto end;
}
keyfile = opt_arg();
Expand Down Expand Up @@ -428,13 +428,13 @@ int smime_main(int argc, char **argv)
if (sksigners == NULL
&& (sksigners = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(sksigners, signerfile))
if (sk_OPENSSL_STRING_push(sksigners, signerfile) <= 0)
goto end;
if (!skkeys && (skkeys = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!keyfile)
keyfile = signerfile;
if (!sk_OPENSSL_STRING_push(skkeys, keyfile))
if (sk_OPENSSL_STRING_push(skkeys, keyfile) <= 0)
goto end;
}
if (sksigners == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/x509/by_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static int by_store_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argp,
uris = sk_OPENSSL_STRING_new_null();
X509_LOOKUP_set_method_data(ctx, uris);
}
if (!sk_OPENSSL_STRING_push(uris, data)) {
if (sk_OPENSSL_STRING_push(uris, data) <= 0) {
OPENSSL_free(data);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion test/evp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static int ctrladd(STACK_OF(OPENSSL_STRING) *controls, const char *value)
if (data == NULL)
return -1;

if (!sk_OPENSSL_STRING_push(controls, data)) {
if (sk_OPENSSL_STRING_push(controls, data) <= 0) {
OPENSSL_free(data);
return 0;
}
Expand Down

0 comments on commit 36bee2e

Please sign in to comment.