Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1635083 > unrolled thread
| Started by | Colin King <colin.king@canonical.com> |
|---|---|
| First post | 2017-05-03 17:50 +0200 |
| Last post | 2017-05-03 18:00 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] firmware: Google VPD: fix error handling on allocation failures Colin King <colin.king@canonical.com> - 2017-05-03 17:50 +0200
Re: [PATCH] firmware: Google VPD: fix error handling on allocation failures walter harms <wharms@bfs.de> - 2017-05-03 18:00 +0200
| From | Colin King <colin.king@canonical.com> |
|---|---|
| Date | 2017-05-03 17:50 +0200 |
| Subject | [PATCH] firmware: Google VPD: fix error handling on allocation failures |
| Message-ID | <tD4Hn-7iw-5@gated-at.bofh.it> |
From: Colin Ian King <colin.king@canonical.com>
Fix two allocation failure checks. Firstly, ensure info is checked
for a failed allocation; this fixes a potential null pointer
dereference issue on info->key. Secondly, free info is info->key
fails to allocate to fix a memory leak.
Detected by CoverityScan, CID#1430064 ("Resource Leak")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/firmware/google/vpd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index 3ce813110d5e..2eb15b1dabcc 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -116,9 +116,13 @@ static int vpd_section_attrib_add(const u8 *key, s32 key_len,
return VPD_OK;
info = kzalloc(sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
info->key = kzalloc(key_len + 1, GFP_KERNEL);
- if (!info->key)
+ if (!info->key) {
+ kfree(info);
return -ENOMEM;
+ }
memcpy(info->key, key, key_len);
--
2.11.0
[toc] | [next] | [standalone]
| From | walter harms <wharms@bfs.de> |
|---|---|
| Date | 2017-05-03 18:00 +0200 |
| Subject | Re: [PATCH] firmware: Google VPD: fix error handling on allocation failures |
| Message-ID | <tD4R5-7ok-39@gated-at.bofh.it> |
| In reply to | #1635083 |
Am 03.05.2017 17:49, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
>
> Fix two allocation failure checks. Firstly, ensure info is checked
> for a failed allocation; this fixes a potential null pointer
> dereference issue on info->key. Secondly, free info is info->key
> fails to allocate to fix a memory leak.
>
> Detected by CoverityScan, CID#1430064 ("Resource Leak")
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/firmware/google/vpd.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
> index 3ce813110d5e..2eb15b1dabcc 100644
> --- a/drivers/firmware/google/vpd.c
> +++ b/drivers/firmware/google/vpd.c
> @@ -116,9 +116,13 @@ static int vpd_section_attrib_add(const u8 *key, s32 key_len,
> return VPD_OK;
>
> info = kzalloc(sizeof(*info), GFP_KERNEL);
> + if (!info)
> + return -ENOMEM;
> info->key = kzalloc(key_len + 1, GFP_KERNEL);
> - if (!info->key)
> + if (!info->key) {
> + kfree(info);
> return -ENOMEM;
> + }
>
> memcpy(info->key, key, key_len);
>
the use of key_len+1 looks like preparing space for a string.
so kstrdup() seems more fitting. If this is not a string
there is also a kmemdup().
re,
wh
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web