drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf()
Subsystems (3)
PATCH 1/1 drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf()
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.
--- drivers/gpu/drm/nouveau/nvkm/core/enum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/core/enum.c +1 -1
@@ -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;
Signature · 1 line
2.50.1
Quoted 29 lines · 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 <[email protected]>--- drivers/gpu/drm/nouveau/nvkm/core/enum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nvkm/core/enum.c +1
-1@@ -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;Signature · 1 line
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
Quoted 9 lines · 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 <[email protected]>
Applied to drm-misc-next, thanks!