Skip to contentSkip to conversation

dma-buf: heaps: bugfix for selftest failure

PATCH Superseded Leon He 2 participants 3 messages Mar 4, 2020 – Mar 18, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Leon He

author
#0 lore raw

PATCH 1/1 dma-buf: heaps: bugfix for selftest failure

If the 'name' array in check_vgem() was not initialized to null, the value of name[4] may be random. Which will cause strcmp(name, "vgem") failed.

---
 tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +1 -1
index cd5e1f6..21f3d19 100644
@@ -22,7 +22,7 @@
 static int check_vgem(int fd)
 {
 	drm_version_t version = { 0 };
-	char name[5];
+	char name[5] = { 0 };
 	int ret;
 
 	version.name_len = 4;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 3 lines · Leon He

If the 'name' array in check_vgem() was not initialized to null, the value of name[4] may be random. Which will cause strcmp(name, "vgem") failed.

Nit: "to fail" instead of "failed"

Quoted 12 lines
---
  tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +0 -0
index cd5e1f6..21f3d19 100644

tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c line 28

Quoted 8 lines
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +1 -1
@@ -22,7 +22,7 @@
  static int check_vgem(int fd)
  {
  	drm_version_t version = { 0 };
-	char name[5];
+	char name[5] = { 0 };
  	int ret;
 
  	version.name_len = 4;

return !strcmp(name, "vgem");

While you are at it, why not change strcmp() to strncmp()?

thanks,
-- Shuah

#2 lore raw
Quoted 7 lines · Leon He
Quoted 3 lines

If the 'name' array in check_vgem() was not initialized to null, the value of name[4] may be random. Which will cause strcmp(name, "vgem") failed.

Nit: "to fail" instead of "failed"

OK, thanks!

Quoted 20 lines
Quoted 20 lines
---
  tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +1 -1
index cd5e1f6..21f3d19 100644
@@ -22,7 +22,7 @@
  static int check_vgem(int fd)
  {
      drm_version_t version = { 0 };
-     char name[5];
+     char name[5] = { 0 };
      int ret;
 
Quoted 7 lines

tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c line 28

Quoted 2 lines
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +0 -0
      version.name_len = 4;

return !strcmp(name, "vgem");

While you are at it, why not change strcmp() to strncmp()?

OK, I'll change it in patch v3.

thanks,
-- Leon