Skip to content

Commit 79492d5

Browse files
aheevherbertx
authored andcommitted
crypto: asymmetric_keys - fix uninitialized pointers with free attribute
Uninitialized pointers with `__free` attribute can cause undefined behavior as the memory assigned randomly to the pointer is freed automatically when the pointer goes out of scope. crypto/asymmetric_keys doesn't have any bugs related to this as of now, but, it is better to initialize and assign pointers with `__free` attribute in one statement to ensure proper scope-based cleanup Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/ Signed-off-by: Ally Heev <allyheev@gmail.com> Reviewed-by: Ignat Korchagin <ignat@cloudflare.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a26c23e commit 79492d5

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

crypto/asymmetric_keys/x509_cert_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ EXPORT_SYMBOL_GPL(x509_free_certificate);
6060
*/
6161
struct x509_certificate *x509_cert_parse(const void *data, size_t datalen)
6262
{
63-
struct x509_certificate *cert __free(x509_free_certificate);
63+
struct x509_certificate *cert __free(x509_free_certificate) = NULL;
6464
struct x509_parse_context *ctx __free(kfree) = NULL;
6565
struct asymmetric_key_id *kid;
6666
long ret;

crypto/asymmetric_keys/x509_public_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
148148
*/
149149
static int x509_key_preparse(struct key_preparsed_payload *prep)
150150
{
151-
struct x509_certificate *cert __free(x509_free_certificate);
151+
struct x509_certificate *cert __free(x509_free_certificate) = NULL;
152152
struct asymmetric_key_ids *kids __free(kfree) = NULL;
153153
char *p, *desc __free(kfree) = NULL;
154154
const char *q;

0 commit comments

Comments
 (0)