dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf()
@ 2025-07-24 19:59 Seyediman Seyedarab
  2025-08-02 21:24 ` Seyediman Seyedarab
  2025-08-09 12:00 ` Danilo Krummrich
  0 siblings, 2 replies; 3+ messages in thread
From: Seyediman Seyedarab @ 2025-07-24 19:59 UTC (permalink / raw)
  To: lyude, dakr, airlied, simona
  Cc: dri-devel, nouveau, linux-kernel, Seyediman Seyedarab

snprintf() returns the number of characters that *would* have been
written, which can overestimate how much you actually wrote to the
buffer in case of truncation. That leads to 'data += this' advancing
the pointer past the end of the buffer and size going negative.

Switching to scnprintf() prevents potential buffer overflows and ensures
consistent behavior when building the output string.

Signed-off-by: Seyediman Seyedarab <ImanDevel@gmail.com>
---
 drivers/gpu/drm/nouveau/nvkm/core/enum.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/core/enum.c b/drivers/gpu/drm/nouveau/nvkm/core/enum.c
index b9581feb24cc..a23b40b27b81 100644
--- a/drivers/gpu/drm/nouveau/nvkm/core/enum.c
+++ b/drivers/gpu/drm/nouveau/nvkm/core/enum.c
@@ -44,7 +44,7 @@ nvkm_snprintbf(char *data, int size, const struct nvkm_bitfield *bf, u32 value)
 	bool space = false;
 	while (size >= 1 && bf->name) {
 		if (value & bf->mask) {
-			int this = snprintf(data, size, "%s%s",
+			int this = scnprintf(data, size, "%s%s",
 					    space ? " " : "", bf->name);
 			size -= this;
 			data += this;
-- 
2.50.1


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

* Re: [PATCH] drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf()
  2025-07-24 19:59 [PATCH] drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf() Seyediman Seyedarab
@ 2025-08-02 21:24 ` Seyediman Seyedarab
  2025-08-09 12:00 ` Danilo Krummrich
  1 sibling, 0 replies; 3+ messages in thread
From: Seyediman Seyedarab @ 2025-08-02 21:24 UTC (permalink / raw)
  To: lyude, dakr, airlied, simona; +Cc: dri-devel, nouveau, linux-kernel

On 25/07/24 03:59PM, Seyediman Seyedarab wrote:
> snprintf() returns the number of characters that *would* have been
> written, which can overestimate how much you actually wrote to the
> buffer in case of truncation. That leads to 'data += this' advancing
> the pointer past the end of the buffer and size going negative.
> 
> Switching to scnprintf() prevents potential buffer overflows and ensures
> consistent behavior when building the output string.
> 
> Signed-off-by: Seyediman Seyedarab <ImanDevel@gmail.com>
> ---
>  drivers/gpu/drm/nouveau/nvkm/core/enum.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/core/enum.c b/drivers/gpu/drm/nouveau/nvkm/core/enum.c
> index b9581feb24cc..a23b40b27b81 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/core/enum.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/core/enum.c
> @@ -44,7 +44,7 @@ nvkm_snprintbf(char *data, int size, const struct nvkm_bitfield *bf, u32 value)
>  	bool space = false;
>  	while (size >= 1 && bf->name) {
>  		if (value & bf->mask) {
> -			int this = snprintf(data, size, "%s%s",
> +			int this = scnprintf(data, size, "%s%s",
>  					    space ? " " : "", bf->name);
>  			size -= this;
>  			data += this;
> -- 
> 2.50.1
> 

Hi there,

Just following up on this patch. Please let me know if there's any
feedback or if further changes are needed.

Regards,
Seyediman

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

* Re: [PATCH] drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf()
  2025-07-24 19:59 [PATCH] drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf() Seyediman Seyedarab
  2025-08-02 21:24 ` Seyediman Seyedarab
@ 2025-08-09 12:00 ` Danilo Krummrich
  1 sibling, 0 replies; 3+ messages in thread
From: Danilo Krummrich @ 2025-08-09 12:00 UTC (permalink / raw)
  To: Seyediman Seyedarab
  Cc: lyude, airlied, simona, dri-devel, nouveau, linux-kernel

On 7/24/25 9:59 PM, Seyediman Seyedarab wrote:
> snprintf() returns the number of characters that *would* have been
> written, which can overestimate how much you actually wrote to the
> buffer in case of truncation. That leads to 'data += this' advancing
> the pointer past the end of the buffer and size going negative.
> 
> Switching to scnprintf() prevents potential buffer overflows and ensures
> consistent behavior when building the output string.
> 
> Signed-off-by: Seyediman Seyedarab <ImanDevel@gmail.com>

Applied to drm-misc-next, thanks!

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

end of thread, other threads:[~2025-08-09 12:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24 19:59 [PATCH] drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf() Seyediman Seyedarab
2025-08-02 21:24 ` Seyediman Seyedarab
2025-08-09 12:00 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).