tools: gpio: fix buffer overflow and add bounds check
PATCH 1/1 tools: gpio: fix buffer overflow and add bounds check
Replace strcpy() with strncpy() to avoid potential buffer overflow in req.consumer. Also add validation for num_lines to prevent out-of-bounds access to req.offsets.
Fix incorrect ioctl name in error message.
--- tools/gpio/gpio-utils.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
tools/gpio/gpio-utils.c +10 -4
@@ -65,11 +65,15 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || + num_lines ==0 || num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; + ret =asprintf (&chrdev_name,"/dev/%s" , device_name);if (ret <0 )return -ENOMEM ; - fd =open (chrdev_name,0 ); + fd =open (chrdev_name,O_RDONLY );if (fd ==-1 ) { ret = -errno; fprintf(stderr, "Failed to open %s, %s\n",
@@ -78,27 +82,29 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, }memset (&req,0 ,sizeof (req)); +for (i =0 ; i < num_lines; i++) req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strncpy (req.consumer, consumer,sizeof (req.consumer) -1 ); + req.consumer[sizeof (req.consumer) -1 ] ='\0' ; req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);if (ret ==-1 ) { ret = -errno;fprintf (stderr,"Failed to issue %s (%d), %s\n" , -"GPIO_GET_LINE_IOCTL" , ret,strerror (errno)); +"GPIO_V2_GET_LINE_IOCTL" , ret,strerror (errno)); }if (close (fd) ==-1 )perror ("Failed to close GPIO character device file" ); + exit_free_name:free (chrdev_name);return ret <0 ? ret : req.fd; } -/** * gpiotools_set_values() - Set the value of gpio(s) * @fd: The fd returned by
Signature · 1 line
2.54.0
Quoted 11 lines · Zhang Xiaolei
Replace
strcpy()withstrncpy()to avoid potential buffer overflow in req.consumer. Also add validation fornum_linesto prevent out-of-bounds access to req.offsets.Fix incorrect ioctl name in error message.
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
This looks like a patch that could be split, since you're adding NULL pointer checking, a potential overflow fix, and a style fix all into one. I like the idea, but we need to split functional changes.
Quoted 6 lines
tools/gpio/gpio-utils.c +0
-0
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 72
Quoted 8 lines
tools/gpio/gpio-utils.c +4
-0@@ -65,11 +65,15 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || + num_lines ==0 || num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; +
First off, this can be split into a different patch. Secondly, I feel as if we should make two if statements for this, one for the NULL and 0 checking and the other for checking num_lines. And returning -EINVAL will be ambiguous for the caller, so maybe change that.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines,
Quoted 8 lines
tools/gpio/gpio-utils.c +1
-1ret =asprintf (&chrdev_name,"/dev/%s" , device_name);if (ret <0 )return -ENOMEM ; - fd =open (chrdev_name,0 ); + fd =open (chrdev_name,O_RDONLY );
Another thing that can be split.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 86
Quoted 10 lines
tools/gpio/gpio-utils.c +0
-0if (fd ==-1 ) {tools/gpio/gpio-utils.c +1
-0ret = -errno; fprintf(stderr, "Failed to open %s, %s\n",@@ -78,27 +82,29 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, }memset (&req,0 ,sizeof (req)); +
This seems like a stray change.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 93
Quoted 9 lines
tools/gpio/gpio-utils.c +2
-1for (i =0 ; i < num_lines; i++) req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strncpy (req.consumer, consumer,sizeof (req.consumer) -1 ); + req.consumer[sizeof (req.consumer) -1 ] ='\0' ;
We already invented a solution for this in the form of strscpy(), so please change this to use that instead, something like:
strscpy(req.consumer, consumer, sizeof(req.consumer));
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 100
Quoted 10 lines
tools/gpio/gpio-utils.c +1
-1req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);if (ret ==-1 ) { ret = -errno;fprintf (stderr,"Failed to issue %s (%d), %s\n" , -"GPIO_GET_LINE_IOCTL" , ret,strerror (errno)); +"GPIO_V2_GET_LINE_IOCTL" , ret,strerror (errno));
Another thing that could be split.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines,
Quoted 7 lines
tools/gpio/gpio-utils.c +1
-0}if (close (fd) ==-1 )perror ("Failed to close GPIO character device file" ); +
Might be another stray change.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 101
Quoted 7 lines
tools/gpio/gpio-utils.c +0
-1exit_free_name:free (chrdev_name);return ret <0 ? ret : req.fd; } -
Maybe another stray change?
Quoted 4 lines
/**
*gpiotools_set_values()- Set the value of gpio(s)
* @fd: The fd returned by
I like the idea, but we should be splitting some of these changes to follow the atomic commits idea of the kernel.
best regards,
maxwell
Hi Maxwell,
Quoted 3 lines
This looks like a patch that could be split, since you're adding NULL pointer checking, a potential overflow fix, and a style fix all into one. I like the idea, but we need to split functional changes.
Thanks for the review. I agree that these changes should be split into smaller atomic patches. I will prepare a v2 series.
Quoted 4 lines
First off, this can be split into a different patch. Secondly, I feel as if we should make two if statements for this, one for the NULL and 0 checking and the other for checking
num_lines. And returning-EINVALwill be ambiguous for the caller, so maybe change that.
Got it. I will split the argument validation and the num_lines bounds check, and reconsider the return values.
Quoted 1 line
Another thing that can be split.
I will drop the O_RDONLY change from v2 unless it is useful as a separate cleanup.
Quoted 1 line
This seems like a stray change.
Thanks, I will remove unrelated whitespace changes.
Quoted 2 lines
We already invented a solution for this in the form of
strscpy(), so please change this to use that instead
Agreed. I will use strscpy() in v2.
Quoted 1 line
Another thing that could be split.
I will split the ioctl name fix into a separate patch.
Thanks,
Zhang Xiaolei
Quoted 102 lines · Maxwell Doose
Quoted 11 lines · Zhang Xiaolei
Replace
strcpy()withstrncpy()to avoid potential buffer overflow in req.consumer. Also add validation fornum_linesto prevent out-of-bounds access to req.offsets.Fix incorrect ioctl name in error message.
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)This looks like a patch that could be split, since you're adding NULL pointer checking, a potential overflow fix, and a style fix all into one. I like the idea, but we need to split functional changes.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 72
Quoted 13 lines
tools/gpio/gpio-utils.c +4
-0@@ -65,11 +65,15 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || + num_lines ==0 || num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; +First off, this can be split into a different patch. Secondly, I feel as if we should make two if statements for this, one for the NULL and 0 checking and the other for checking
num_lines. And returning-EINVALwill be ambiguous for the caller, so maybe change that.tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines,
Quoted 7 lines
tools/gpio/gpio-utils.c +1
-1ret =asprintf (&chrdev_name,"/dev/%s" , device_name);if (ret <0 )return -ENOMEM ; - fd =open (chrdev_name,0 ); + fd =open (chrdev_name,O_RDONLY );Another thing that can be split.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 86
Quoted 9 lines
tools/gpio/gpio-utils.c +0
-0if (fd ==-1 ) {ret = -errno;
fprintf(stderr, "Failed to open %s, %s\n",tools/gpio/gpio-utils.c +1
-0@@ -78,27 +82,29 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, }memset (&req,0 ,sizeof (req)); +This seems like a stray change.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 93
Quoted 8 lines
tools/gpio/gpio-utils.c +2
-1for (i =0 ; i < num_lines; i++) req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strncpy (req.consumer, consumer,sizeof (req.consumer) -1 ); + req.consumer[sizeof (req.consumer) -1 ] ='\0' ;We already invented a solution for this in the form of
strscpy(), so please change this to use that instead, something like:strscpy(req.consumer, consumer, sizeof(req.consumer));tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 100
Quoted 9 lines
tools/gpio/gpio-utils.c +1
-1req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);if (ret ==-1 ) { ret = -errno;fprintf (stderr,"Failed to issue %s (%d), %s\n" , -"GPIO_GET_LINE_IOCTL" , ret,strerror (errno)); +"GPIO_V2_GET_LINE_IOCTL" , ret,strerror (errno));Another thing that could be split.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines,
Quoted 6 lines
tools/gpio/gpio-utils.c +1
-0}if (close (fd) ==-1 )perror ("Failed to close GPIO character device file" ); +Might be another stray change.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 101
Quoted 6 lines
tools/gpio/gpio-utils.c +0
-1exit_free_name:free (chrdev_name);return ret <0 ? ret : req.fd; } -Maybe another stray change?
Quoted 3 lines
/**
*gpiotools_set_values()- Set the value of gpio(s)
* @fd: The fd returned byI like the idea, but we should be splitting some of these changes to follow the atomic commits idea of the kernel.
best regards,
maxwell
Hi Maxwell,
Quoted 3 lines
This looks like a patch that could be split, since you're adding NULL pointer checking, a potential overflow fix, and a style fix all into one. I like the idea, but we need to split functional changes.
Thanks for the review. I agree that these changes should be split into smaller atomic patches. I will prepare a v2 series.
Quoted 4 lines
First off, this can be split into a different patch. Secondly, I feel as if we should make two if statements for this, one for the NULL and 0 checking and the other for checking
num_lines. And returning-EINVALwill be ambiguous for the caller, so maybe change that.
Got it. I will split the argument validation and the num_lines bounds check, and reconsider the return values.
Quoted 1 line
Another thing that can be split.
I will drop the O_RDONLY change from v2 unless it is useful as a separate cleanup.
Quoted 1 line
This seems like a stray change.
Thanks, I will remove unrelated whitespace changes.
Quoted 2 lines
We already invented a solution for this in the form of
strscpy(), so please change this to use that instead
Agreed. I will use strscpy() in v2.
Quoted 1 line
Another thing that could be split.
I will split the ioctl name fix into a separate patch.
Thanks,
Zhang Xiaolei
Quoted 102 lines · Maxwell Doose
Quoted 11 lines · Zhang Xiaolei
Replace
strcpy()withstrncpy()to avoid potential buffer overflow in req.consumer. Also add validation fornum_linesto prevent out-of-bounds access to req.offsets.Fix incorrect ioctl name in error message.
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)This looks like a patch that could be split, since you're adding NULL pointer checking, a potential overflow fix, and a style fix all into one. I like the idea, but we need to split functional changes.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 72
Quoted 13 lines
tools/gpio/gpio-utils.c +4
-0@@ -65,11 +65,15 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || + num_lines ==0 || num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; +First off, this can be split into a different patch. Secondly, I feel as if we should make two if statements for this, one for the NULL and 0 checking and the other for checking
num_lines. And returning-EINVALwill be ambiguous for the caller, so maybe change that.tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines,
Quoted 7 lines
tools/gpio/gpio-utils.c +1
-1ret =asprintf (&chrdev_name,"/dev/%s" , device_name);if (ret <0 )return -ENOMEM ; - fd =open (chrdev_name,0 ); + fd =open (chrdev_name,O_RDONLY );Another thing that can be split.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 86
Quoted 9 lines
tools/gpio/gpio-utils.c +0
-0if (fd ==-1 ) {ret = -errno;
fprintf(stderr, "Failed to open %s, %s\n",tools/gpio/gpio-utils.c +1
-0@@ -78,27 +82,29 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, }memset (&req,0 ,sizeof (req)); +This seems like a stray change.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 93
Quoted 8 lines
tools/gpio/gpio-utils.c +2
-1for (i =0 ; i < num_lines; i++) req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strncpy (req.consumer, consumer,sizeof (req.consumer) -1 ); + req.consumer[sizeof (req.consumer) -1 ] ='\0' ;We already invented a solution for this in the form of
strscpy(), so please change this to use that instead, something like:strscpy(req.consumer, consumer, sizeof(req.consumer));tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 100
Quoted 9 lines
tools/gpio/gpio-utils.c +1
-1req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);if (ret ==-1 ) { ret = -errno;fprintf (stderr,"Failed to issue %s (%d), %s\n" , -"GPIO_GET_LINE_IOCTL" , ret,strerror (errno)); +"GPIO_V2_GET_LINE_IOCTL" , ret,strerror (errno));Another thing that could be split.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines,
Quoted 6 lines
tools/gpio/gpio-utils.c +1
-0}if (close (fd) ==-1 )perror ("Failed to close GPIO character device file" ); +Might be another stray change.
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 101
Quoted 6 lines
tools/gpio/gpio-utils.c +0
-1exit_free_name:free (chrdev_name);return ret <0 ? ret : req.fd; } -Maybe another stray change?
Quoted 3 lines
/**
*gpiotools_set_values()- Set the value of gpio(s)
* @fd: The fd returned byI like the idea, but we should be splitting some of these changes to follow the atomic commits idea of the kernel.
best regards,
maxwell
PATCH v2 1/3 tools: gpio: use strscpy() for consumer name
In reply to Zhang XiaoleiReplace strcpy() with strscpy() to avoid potential buffer overflow when copying the consumer string.
--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/gpio/gpio-utils.c +1 -1
@@ -82,7 +82,7 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strcpy (req.consumer, consumer,sizeof (req.consumer)); req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);
Signature · 1 line
2.34.1
PATCH v2 2/3 tools: gpio: validate arguments in gpiotools_request_line
Add validation for input pointers and number of lines.
--- tools/gpio/gpio-utils.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/gpio/gpio-utils.c +6 -0
@@ -65,6 +65,12 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || !num_lines) +return -EINVAL ; + +if (num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; + ret =asprintf (&chrdev_name,"/dev/%s" , device_name);if (ret <0 )return -ENOMEM ;
Signature · 1 line
2.34.1
Re: [PATCH v2 2/3] tools: gpio: validate arguments in gpiotools_request_line
Quoted 3 lines · Zhang Xiaolei
Add validation for input pointers and number of lines.
Perhaps make the commit message more descriptive?
Quoted 11 lines
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/gpio/gpio-utils.c +0
-0
tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 73
Quoted 9 lines
tools/gpio/gpio-utils.c +6
-0@@ -65,6 +65,12 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || !num_lines) +return -EINVAL ; + +if (num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; +
I'm wondering if we might want to use ERANGE here for the num_lines > GPIO_V2_LINES_MAX check instead of EINVAL.
best regards,
maxwell
Re: [PATCH v2 2/3] tools: gpio: validate arguments in gpiotools_request_line
OK, I will redo it, thanks.
Best regards,
Zhang Xiaolei
Quoted 29 lines · Maxwell Doose
Quoted 2 lines · Zhang Xiaolei
Add validation for input pointers and number of lines.
Perhaps make the commit message more descriptive?
Quoted 10 lines
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/gpio/gpio-utils.c +0
-0tools/gpio/gpio-utils.c int gpiotools_request_line(const char *device_name, unsigned int *lines, · line 73
Quoted 9 lines
tools/gpio/gpio-utils.c +6
-0@@ -65,6 +65,12 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,int i;int ret; +if (!device_name || !lines || !config || !consumer || !num_lines) +return -EINVAL ; + +if (num_lines >GPIO_V2_LINES_MAX ) +return -EINVAL ; +I'm wondering if we might want to use ERANGE here for the
num_lines>GPIO_V2_LINES_MAXcheck instead of EINVAL.best regards,
maxwell
PATCH v2 3/3 tools: gpio: fix ioctl name in error message
In reply to Zhang XiaoleiUse the correct ioctl name in the error message.
--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/gpio/gpio-utils.c +1 -1
@@ -95,7 +95,7 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,if (ret ==-1 ) { ret = -errno;fprintf (stderr,"Failed to issue %s (%d), %s\n" , -"GPIO_GET_LINE_IOCTL" , ret,strerror (errno)); +"GPIO_V2_GET_LINE_IOCTL" , ret,strerror (errno)); }if (close (fd) ==-1 )
Signature · 1 line
2.34.1
Re: [PATCH v2 3/3] tools: gpio: fix ioctl name in error message
Hi Zhang,
Quoted 8 lines · Zhang Xiaolei
Use the correct ioctl name in the error message.
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[snip]
Patch looks technically good but when I meant split these patches I meant into entirely separate patches. Please split this away from the patch series.
best regards,
max
Re: [PATCH v2 3/3] tools: gpio: fix ioctl name in error message
Hi, bro, I will redo it, thanks for the reminder.
Best regards
Zhang Xiaolei
Quoted 18 lines · Maxwell Doose
Hi Zhang,
Quoted 7 lines · Zhang Xiaolei
Use the correct ioctl name in the error message.
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)[snip]
Patch looks technically good but when I meant split these patches I meant into entirely separate patches. Please split this away from the patch series.
best regards,
max
PATCH v3 1/1 tools: gpio: fix ioctl name in error message
In reply to Zhang XiaoleiUse the correct ioctl name in the error message.
--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/gpio/gpio-utils.c +1 -1
@@ -95,7 +95,7 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines,if (ret ==-1 ) { ret = -errno;fprintf (stderr,"Failed to issue %s (%d), %s\n" , -"GPIO_GET_LINE_IOCTL" , ret,strerror (errno)); +"GPIO_V2_GET_LINE_IOCTL" , ret,strerror (errno)); }if (close (fd) ==-1 )
Signature · 1 line
2.34.1
Re: [PATCH v2 1/3] tools: gpio: use strscpy() for consumer name
In reply to Zhang XiaoleiQuoted 2 lines · On Mon, 4 May 2026 15:50:34 +0800 Zhang Xiaolei <[email protected]> wrote:
Replace
strcpy()withstrscpy()to avoid potential buffer overflow when copying the consumer string.
You ought to run code before submitting patches.
This wasn't even compiled.
-- David
Quoted 19 lines
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/gpio/gpio-utils.c +1
-1@@ -82,7 +82,7 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strcpy (req.consumer, consumer,sizeof (req.consumer)); req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);
Re: [PATCH v2 1/3] tools: gpio: use strscpy() for consumer name
OK, I will check it next time, thanks for the reminder.
Best regards
Zhang Xiaolei
Quoted 28 lines · David Laight
Quoted 2 lines · On Mon, 4 May 2026 15:50:34 +0800 Zhang Xiaolei <[email protected]> wrote:
Replace
strcpy()withstrscpy()to avoid potential buffer overflow when copying the consumer string.You ought to run code before submitting patches.
This wasn't even compiled.-- David
Quoted 18 lines
Signed-off-by Zhang Xiaolei <[email protected]>--- tools/gpio/gpio-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/gpio/gpio-utils.c +1
-1@@ -82,7 +82,7 @@ int gpiotools_request_line(const char *device_name, unsigned int *lines, req.offsets[i] = lines[i]; req.config = *config; -strcpy (req.consumer, consumer); +strcpy (req.consumer, consumer,sizeof (req.consumer)); req.num_lines = num_lines; ret =ioctl (fd,GPIO_V2_GET_LINE_IOCTL , &req);