[PATCH] ceph: Check memory allocation result

Subsystems: ceph common code (libceph), the rest

STALE3121d

2 messages, 2 authors, 2018-01-29 · open the first message on its own page

[PATCH] ceph: Check memory allocation result

From: Chengguang Xu <hidden>
Date: 2018-01-26 07:55:46

Should check result of kstrndup() in case of memory allocation failure.

Signed-off-by: Chengguang Xu <redacted>
---
 net/ceph/ceph_common.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 5c036d2..1e492ef 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -421,6 +421,10 @@ struct ceph_options *
 			opt->name = kstrndup(argstr[0].from,
 					      argstr[0].to-argstr[0].from,
 					      GFP_KERNEL);
+			if (!opt->name) {
+				err = -ENOMEM;
+				goto out;
+			}
 			break;
 		case Opt_secret:
 		        opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
-- 
1.8.3.1

Re: [PATCH] ceph: Check memory allocation result

From: Ilya Dryomov <idryomov@gmail.com>
Date: 2018-01-29 16:42:41

On Fri, Jan 26, 2018 at 7:54 AM, Chengguang Xu [off-list ref] wrote:
quoted hunk
Should check result of kstrndup() in case of memory allocation failure.

Signed-off-by: Chengguang Xu <redacted>
---
 net/ceph/ceph_common.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 5c036d2..1e492ef 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -421,6 +421,10 @@ struct ceph_options *
                        opt->name = kstrndup(argstr[0].from,
                                              argstr[0].to-argstr[0].from,
                                              GFP_KERNEL);
+                       if (!opt->name) {
+                               err = -ENOMEM;
+                               goto out;
+                       }
                        break;
                case Opt_secret:
                        opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
Applied.

Thanks,

                Ilya
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help