DriverDev-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] staging: rtl8712: Replace snprintf with scnprintf
@ 2019-09-10 18:49 Rohit Sarkar
  2019-09-10 18:55 ` Rohit Sarkar
  0 siblings, 1 reply; 2+ messages in thread
From: Rohit Sarkar @ 2019-09-10 18:49 UTC (permalink / raw)
  To: gregkh, larry.finger, florian.c.schilhabel, driverdev-devel

When the number of bytes to be printed exceeds the limit snprintf
returns the number of bytes that would have been printed (if there was
no truncation). This might cause issues, hence use scnprintf which
returns the actual number of bytes printed to buffer always.

Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
---
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index b08b9a191a34..ff5edcaba64d 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -142,7 +142,7 @@ static noinline_for_stack char *translate_scan_wpa(struct iw_request_info *info,
 		memset(buf, 0, MAX_WPA_IE_LEN);
 		n = sprintf(buf, "wpa_ie=");
 		for (i = 0; i < wpa_len; i++) {
-			n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
+			n += scnprintf(buf + n, MAX_WPA_IE_LEN - n,
 						"%02x", wpa_ie[i]);
 			if (n >= MAX_WPA_IE_LEN)
 				break;
@@ -162,7 +162,7 @@ static noinline_for_stack char *translate_scan_wpa(struct iw_request_info *info,
 		memset(buf, 0, MAX_WPA_IE_LEN);
 		n = sprintf(buf, "rsn_ie=");
 		for (i = 0; i < rsn_len; i++) {
-			n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
+			n += scnprintf(buf + n, MAX_WPA_IE_LEN - n,
 						"%02x", rsn_ie[i]);
 			if (n >= MAX_WPA_IE_LEN)
 				break;
-- 
2.17.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: rtl8712: Replace snprintf with scnprintf
  2019-09-10 18:49 [PATCH] staging: rtl8712: Replace snprintf with scnprintf Rohit Sarkar
@ 2019-09-10 18:55 ` Rohit Sarkar
  0 siblings, 0 replies; 2+ messages in thread
From: Rohit Sarkar @ 2019-09-10 18:55 UTC (permalink / raw)
  To: gregkh, Larry.Finger, florian.c.schilhabel, driverdev-devel

Resending as I made a typo in Larry's email id.

On Wed, Sep 11, 2019 at 12:19:31AM +0530, Rohit Sarkar wrote:
> When the number of bytes to be printed exceeds the limit snprintf
> returns the number of bytes that would have been printed (if there was
> no truncation). This might cause issues, hence use scnprintf which
> returns the actual number of bytes printed to buffer always.
> 
> Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
> ---
>  drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> index b08b9a191a34..ff5edcaba64d 100644
> --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> @@ -142,7 +142,7 @@ static noinline_for_stack char *translate_scan_wpa(struct iw_request_info *info,
>  		memset(buf, 0, MAX_WPA_IE_LEN);
>  		n = sprintf(buf, "wpa_ie=");
>  		for (i = 0; i < wpa_len; i++) {
> -			n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
> +			n += scnprintf(buf + n, MAX_WPA_IE_LEN - n,
>  						"%02x", wpa_ie[i]);
>  			if (n >= MAX_WPA_IE_LEN)
>  				break;
> @@ -162,7 +162,7 @@ static noinline_for_stack char *translate_scan_wpa(struct iw_request_info *info,
>  		memset(buf, 0, MAX_WPA_IE_LEN);
>  		n = sprintf(buf, "rsn_ie=");
>  		for (i = 0; i < rsn_len; i++) {
> -			n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
> +			n += scnprintf(buf + n, MAX_WPA_IE_LEN - n,
>  						"%02x", rsn_ie[i]);
>  			if (n >= MAX_WPA_IE_LEN)
>  				break;
> -- 
> 2.17.1
> 
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-10 18:49 [PATCH] staging: rtl8712: Replace snprintf with scnprintf Rohit Sarkar
2019-09-10 18:55 ` Rohit Sarkar

DriverDev-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/driverdev-devel/0 driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ https://lore.kernel.org/driverdev-devel \
		driverdev-devel@linuxdriverproject.org devel@driverdev.osuosl.org driverdev-devel@archiver.kernel.org
	public-inbox-index driverdev-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxdriverproject.driverdev-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox