Module: Mesa
Branch: main
Commit: 477b310dfd5ec662837e2e1cde87b9416dbcf67f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=477b310dfd5ec662837e2e1cde87b9416dbcf67f

Author: Rhys Perry <[email protected]>
Date:   Wed Sep 27 15:55:25 2023 +0100

util: skip zero-sized SHA1Update

Fixes UBSan error:
src/util/sha1/sha1.c:140:8: runtime error: null pointer passed as argument 2, 
which is declared to never be null

Signed-off-by: Rhys Perry <[email protected]>
Reviewed-by: Timur Kristóf <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25853>

---

 src/util/mesa-sha1.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/mesa-sha1.h b/src/util/mesa-sha1.h
index 809fabc525f..c264927d572 100644
--- a/src/util/mesa-sha1.h
+++ b/src/util/mesa-sha1.h
@@ -44,7 +44,8 @@ _mesa_sha1_init(struct mesa_sha1 *ctx)
 static inline void
 _mesa_sha1_update(struct mesa_sha1 *ctx, const void *data, size_t size)
 {
-   SHA1Update(ctx, (const unsigned char *)data, size);
+   if (size)
+      SHA1Update(ctx, (const unsigned char *)data, size);
 }
 
 static inline void

Reply via email to