* [PATCH] Utils: Change sprintf to snprintf
@ 2021-08-12 11:48 Mateusz Kusiak
2021-08-13 19:21 ` Jes Sorensen
0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Kusiak @ 2021-08-12 11:48 UTC (permalink / raw)
To: linux-raid; +Cc: jes
Using sprintf can cause segmentation fault by exceeding the size of buffer array.
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
---
util.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util.c b/util.c
index cdf1da24..ea07277c 100644
--- a/util.c
+++ b/util.c
@@ -947,12 +947,12 @@ dev_t devnm2devid(char *devnm)
/* First look in /sys/block/$DEVNM/dev for %d:%d
* If that fails, try parsing out a number
*/
- char path[100];
+ char path[PATH_MAX];
char *ep;
int fd;
int mjr,mnr;
- sprintf(path, "/sys/block/%s/dev", devnm);
+ snprintf(path, sizeof(path), "/sys/block/%s/dev", devnm);
fd = open(path, O_RDONLY);
if (fd >= 0) {
char buf[20];
--
2.26.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Utils: Change sprintf to snprintf
2021-08-12 11:48 [PATCH] Utils: Change sprintf to snprintf Mateusz Kusiak
@ 2021-08-13 19:21 ` Jes Sorensen
0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2021-08-13 19:21 UTC (permalink / raw)
To: Mateusz Kusiak, linux-raid
On 8/12/21 7:48 AM, Mateusz Kusiak wrote:
> Using sprintf can cause segmentation fault by exceeding the size of buffer array.
>
> Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
> ---
> util.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Applied, thanks!
Jes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-08-13 19:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 11:48 [PATCH] Utils: Change sprintf to snprintf Mateusz Kusiak
2021-08-13 19:21 ` Jes Sorensen
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.