All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drivers/base/auxiliary: check return value of strrchr()
@ 2022-09-04  0:51 Li Zhong
  2022-09-04  6:20 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zhong @ 2022-09-04  0:51 UTC (permalink / raw)
  To: linux-kernel; +Cc: gregkh, rafael, Li Zhong

The return value of strrchr() could be NULL, which will cause invalid
offset in (int)(p - name). So we check it here.

Signed-off-by: Li Zhong <floridsleeves@gmail.com>
---
 drivers/base/auxiliary.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
index 8c5e65930617..2ec0306bfba3 100644
--- a/drivers/base/auxiliary.c
+++ b/drivers/base/auxiliary.c
@@ -191,6 +191,8 @@ static int auxiliary_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 	name = dev_name(dev);
 	p = strrchr(name, '.');
+	if (!p)
+		return -EINVAL;
 
 	return add_uevent_var(env, "MODALIAS=%s%.*s", AUXILIARY_MODULE_PREFIX,
 			      (int)(p - name), name);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] drivers/base/auxiliary: check return value of strrchr()
  2022-09-04  0:51 [PATCH v2] drivers/base/auxiliary: check return value of strrchr() Li Zhong
@ 2022-09-04  6:20 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-09-04  6:20 UTC (permalink / raw)
  To: Li Zhong; +Cc: linux-kernel, rafael

On Sat, Sep 03, 2022 at 05:51:56PM -0700, Li Zhong wrote:
> The return value of strrchr() could be NULL, which will cause invalid
> offset in (int)(p - name). So we check it here.
> 
> Signed-off-by: Li Zhong <floridsleeves@gmail.com>
> ---
>  drivers/base/auxiliary.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
> index 8c5e65930617..2ec0306bfba3 100644
> --- a/drivers/base/auxiliary.c
> +++ b/drivers/base/auxiliary.c
> @@ -191,6 +191,8 @@ static int auxiliary_uevent(struct device *dev, struct kobj_uevent_env *env)
>  
>  	name = dev_name(dev);
>  	p = strrchr(name, '.');
> +	if (!p)
> +		return -EINVAL;

How can that ever happen?  For what device will that be triggered?

And again, please follow Documentation/process/researcher-guidelines.rst

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-04  6:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04  0:51 [PATCH v2] drivers/base/auxiliary: check return value of strrchr() Li Zhong
2022-09-04  6:20 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.