copperplate: Handle errors properly in get_session_label
PATCH 1/1 copperplate: Handle errors properly in get_session_label
From: Jan Kiszka <[email protected]>
strdup may fail. And if we fail otherwise later, session will leak. The second issue was reported by clang-9 scan-build.
---
This and the other one were the only issues worth addressing - or even valid at all. Even without issues with the API and sycall ABI, scan- build tends to have quite a few false positives.
lib/copperplate/init.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/copperplate/init.c +6 -1
@@ -155,6 +155,8 @@ static int get_session_label(const char *optarg)int ret; session =strdup (optarg); +if (!session) +return -ENOMEM ; grpname =strrchr (session,'/' );if (grpname ==NULL ) goto no_group;
@@ -163,8 +165,10 @@ static int get_session_label(const char *optarg)if (isdigit (*grpname)) { gid = (gid_t )strtol (grpname, &p,10 ); -if (*p) +if (*p) { +free (session);return -EINVAL ; + } errno =0 ; grp =getgrgid (gid); }else {
@@ -175,6 +179,7 @@ static int get_session_label(const char *optarg)if (grp ==NULL ) { ret = errno ? -errno : -EINVAL ;warning ("invalid group %s" , grpname); +free (session);return ret; }
Signature · 6 lines
2.16.4 -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 42 lines · Jan Kiszka via Xenomai
From: Jan Kiszka <[email protected]>
strdup may fail. And if we fail otherwise later, session will leak. The second issue was reported by clang-9 scan-build.
Signed-off-by Jan Kiszka <[email protected]>---
This and the other one were the only issues worth addressing - or even valid at all. Even without issues with the API and sycall ABI, scan- build tends to have quite a few false positives.
lib/copperplate/init.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/copperplate/init.c +5
-1@@ -155,6 +155,8 @@ static int get_session_label(const char *optarg)int ret; session =strdup (optarg); +if (!session) +return -ENOMEM ; grpname =strrchr (session,'/' );if (grpname ==NULL ) goto no_group;@@ -163,8 +165,10 @@ static int get_session_label(const char *optarg)if (isdigit (*grpname)) { gid = (gid_t )strtol (grpname, &p,10 ); -if (*p) +if (*p) { +free (session);return -EINVAL ; + } errno =0 ; grp =getgrgid (gid); }else {
lib/copperplate/init.c static int get_session_label(const char *optarg) · line 185
Quoted 7 lines
lib/copperplate/init.c +1
-0@@ -175,6 +179,7 @@ static int get_session_label(const char *optarg)if (grp ==NULL ) { ret = errno ? -errno : -EINVAL ;warning ("invalid group %s" , grpname); +free (session);return ret; }
Ack.
Signature · 1 line
Philippe.
question about ipipe
In the ipipe some local_irq_enable will be replace by enable_local_irqs, some are not。
how to determine whether it needs to be replaced ? Is there any document ?
*Linx Software Corportaion Sichuan Branch
Name:wujie duan
Tel:028-65182023-6202
E-mail: [email protected]
*
Re: question about ipipe
Please do not reply to unrelated threads when starting a new topic.
Quoted 2 lines · duanwujie via Xenomai
In the ipipe some
local_irq_enablewill be replace byenable_local_irqs, some are not。
enable_local_irqs is a macro local to arch/x86/entry/common.c. Generally, the replacement is hard_local_irq_...
Quoted 3 lines
how to determine whether it needs to be replaced ? Is there any document ?
At this level, we do not have documents. The common reasons to "harden" interrupts disabling over I-pipe are:
- sharing of basic hardware resources with Linux, e.g. interrupt controllers and timers
- common code paths in context setting or switching, specifically around MMU and FPU
- sensitive exception, interrupt and syscall entry/exit paths
And then there some special cases, like
- tracing
- KVM preemption
HTH,
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux