* [PATCH] rbd: replace strcpy() with strscpy()
@ 2025-05-14 18:20 Siddarth Gundu
2025-05-14 18:52 ` Alex Elder
0 siblings, 1 reply; 3+ messages in thread
From: Siddarth Gundu @ 2025-05-14 18:20 UTC (permalink / raw)
To: idryomov
Cc: dongsheng.yang, axboe, ceph-devel, linux-block, linux-kernel,
Siddarth Gundu
strcpy() is deprecated; use strscpy() instead.
Both the destination and source buffer are of fixed length
so strscpy with 2-arguments is used.
Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Siddarth Gundu <siddarthsgml@gmail.com>
---
drivers/block/rbd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index faafd7ff43d6..92b38972db1c 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -39,6 +39,7 @@
#include <linux/kernel.h>
#include <linux/device.h>
+#include <linux/string.h>
#include <linux/module.h>
#include <linux/blk-mq.h>
#include <linux/fs.h>
@@ -3654,7 +3655,7 @@ static void __rbd_lock(struct rbd_device *rbd_dev, const char *cookie)
struct rbd_client_id cid = rbd_get_cid(rbd_dev);
rbd_dev->lock_state = RBD_LOCK_STATE_LOCKED;
- strcpy(rbd_dev->lock_cookie, cookie);
+ strscpy(rbd_dev->lock_cookie, cookie);
rbd_set_owner_cid(rbd_dev, &cid);
queue_work(rbd_dev->task_wq, &rbd_dev->acquired_lock_work);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rbd: replace strcpy() with strscpy()
2025-05-14 18:20 [PATCH] rbd: replace strcpy() with strscpy() Siddarth Gundu
@ 2025-05-14 18:52 ` Alex Elder
2025-05-15 14:23 ` Siddarth Gundu
0 siblings, 1 reply; 3+ messages in thread
From: Alex Elder @ 2025-05-14 18:52 UTC (permalink / raw)
To: Siddarth Gundu, idryomov
Cc: dongsheng.yang, axboe, ceph-devel, linux-block, linux-kernel
On 5/14/25 1:20 PM, Siddarth Gundu wrote:
> strcpy() is deprecated; use strscpy() instead.
>
> Both the destination and source buffer are of fixed length
> so strscpy with 2-arguments is used.
>
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Siddarth Gundu <siddarthsgml@gmail.com>
> ---
> drivers/block/rbd.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index faafd7ff43d6..92b38972db1c 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -39,6 +39,7 @@
>
> #include <linux/kernel.h>
> #include <linux/device.h>
> +#include <linux/string.h>
> #include <linux/module.h>
> #include <linux/blk-mq.h>
> #include <linux/fs.h>
> @@ -3654,7 +3655,7 @@ static void __rbd_lock(struct rbd_device *rbd_dev, const char *cookie)
Could the cookie argument possibly be defined with
its size? I.e.:
__rbd_lock(struct rbd_device *rbd_dev, const char cookie[32])
I see all the callers pass an array that's 32 characters,
but the function argument doesn't guarantee that.
You could also abstract the cookie with a typedef and
operations on it.
-Alex
> struct rbd_client_id cid = rbd_get_cid(rbd_dev);
>
> rbd_dev->lock_state = RBD_LOCK_STATE_LOCKED;
> - strcpy(rbd_dev->lock_cookie, cookie);
> + strscpy(rbd_dev->lock_cookie, cookie);
> rbd_set_owner_cid(rbd_dev, &cid);
> queue_work(rbd_dev->task_wq, &rbd_dev->acquired_lock_work);
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rbd: replace strcpy() with strscpy()
2025-05-14 18:52 ` Alex Elder
@ 2025-05-15 14:23 ` Siddarth Gundu
0 siblings, 0 replies; 3+ messages in thread
From: Siddarth Gundu @ 2025-05-15 14:23 UTC (permalink / raw)
To: Alex Elder
Cc: idryomov, dongsheng.yang, axboe, ceph-devel, linux-block,
linux-kernel
On Thu, May 15, 2025 at 12:22 AM Alex Elder <elder@ieee.org> wrote:
>
> On 5/14/25 1:20 PM, Siddarth Gundu wrote:
> > strcpy() is deprecated; use strscpy() instead.
> >
> > Both the destination and source buffer are of fixed length
> > so strscpy with 2-arguments is used.
> >
> > Link: https://github.com/KSPP/linux/issues/88
> > Signed-off-by: Siddarth Gundu <siddarthsgml@gmail.com>
> > ---
> > drivers/block/rbd.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> > index faafd7ff43d6..92b38972db1c 100644
> > --- a/drivers/block/rbd.c
> > +++ b/drivers/block/rbd.c
> > @@ -39,6 +39,7 @@
> >
> > #include <linux/kernel.h>
> > #include <linux/device.h>
> > +#include <linux/string.h>
> > #include <linux/module.h>
> > #include <linux/blk-mq.h>
> > #include <linux/fs.h>
> > @@ -3654,7 +3655,7 @@ static void __rbd_lock(struct rbd_device *rbd_dev, const char *cookie)
>
> Could the cookie argument possibly be defined with
> its size? I.e.:
> __rbd_lock(struct rbd_device *rbd_dev, const char cookie[32])
>
> I see all the callers pass an array that's 32 characters,
> but the function argument doesn't guarantee that.
>
> You could also abstract the cookie with a typedef and
> operations on it.
I see, I will send a v2 patch soon creating a typedef
local to rbd.c Thanks a lot for the review.
--
With Gratitude
Siddarth
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-15 14:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14 18:20 [PATCH] rbd: replace strcpy() with strscpy() Siddarth Gundu
2025-05-14 18:52 ` Alex Elder
2025-05-15 14:23 ` Siddarth Gundu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox