* [PATCH libdrm] drm: handle asprintf() allocation failures in format modifier name functions
@ 2026-04-02 7:52 Rudi Heitbaum
0 siblings, 0 replies; only message in thread
From: Rudi Heitbaum @ 2026-04-02 7:52 UTC (permalink / raw)
To: dri-devel; +Cc: rudi
Check the return value of asprintf() in drmGetFormatModifierNameFromNvidia(),
drmGetFormatModifierNameFromAmlogic(), and drmGetFormatModifierNameFromVivante()
to avoid leaving pointers uninitialized on allocation failure.
asprintf() returns -1 on failure and does not guarantee the output pointer
is set to NULL, which could lead to undefined behavior if the pointer is
used subsequently. Set the pointer to NULL explicitly on failure.
Fixes: -Wunused-result warnings from GCC
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
---
xf86drm.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index d4bfec8a..3199715e 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -348,9 +348,10 @@ drmGetFormatModifierNameFromNvidia(uint64_t modifier)
* testing against TEGRA_TILE */
if ((modifier & 0x10) == 0x10) {
char *mod_nvidia;
- asprintf(&mod_nvidia, "BLOCK_LINEAR_2D,HEIGHT=%"PRIu64",KIND=%"PRIu64","
+ if(asprintf(&mod_nvidia, "BLOCK_LINEAR_2D,HEIGHT=%"PRIu64",KIND=%"PRIu64","
"GEN=%"PRIu64",SECTOR=%"PRIu64",COMPRESSION=%"PRIu64"", height,
- kind, gen, sector, compression);
+ kind, gen, sector, compression) < 0)
+ mod_nvidia = NULL;
return mod_nvidia;
}
@@ -542,7 +543,8 @@ drmGetFormatModifierNameFromAmlogic(uint64_t modifier)
else
opts_str = "0";
- asprintf(&mod_amlogic, "FBC,LAYOUT=%s,OPTIONS=%s", layout_str, opts_str);
+ if(asprintf(&mod_amlogic, "FBC,LAYOUT=%s,OPTIONS=%s", layout_str, opts_str) < 0)
+ mod_amlogic = NULL;
return mod_amlogic;
}
@@ -606,7 +608,8 @@ drmGetFormatModifierNameFromVivante(uint64_t modifier)
break;
}
- asprintf(&mod_vivante, "%s%s%s", color_tiling, tile_status, compression);
+ if(asprintf(&mod_vivante, "%s%s%s", color_tiling, tile_status, compression) < 0)
+ mod_vivante = NULL;
return mod_vivante;
}
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-02 7:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 7:52 [PATCH libdrm] drm: handle asprintf() allocation failures in format modifier name functions Rudi Heitbaum
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.