Skip to contentSkip to conversation

tests/testdisplay: fix heap overflow

PATCH In review Ser, Simon 3 participants 3 messages Mar 20, 2019

lore
Share & tools
lore

Ser, Simon

author
#0 lore raw

PATCH 1/1 tests/testdisplay: fix heap overflow

We need to copy the terminating NULL byte too.

---
 tests/testdisplay.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/testdisplay.c +0 -0
index b3657264..ff208384 100644
@@ -563,17 +563,17 @@ static gboolean input_event(GIOChannel *source,

GIOCondition condition,
return TRUE;
}

-static void enter_exec_path( char **argv )
+static void enter_exec_path(char **argv)
{
char *exec_path = NULL;
char *pos = NULL;
short len_path = 0;
int ret;

- len_path = strlen( argv[0] );
- exec_path = (char*) malloc(len_path);
+ len_path = strlen(argv[0]);
+ exec_path = (char*) malloc(len_path + 1);

- memcpy(exec_path, argv[0], len_path);
+ memcpy(exec_path, argv[0], len_path + 1);
pos = strrchr(exec_path, '/');
if (pos != NULL)
*(pos+1) = '\0';

Signature · 16 lines
2.21.0

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw
Quoted 21 lines · Simon

We need to copy the terminating NULL byte too.

---
 tests/testdisplay.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/testdisplay.c +1 -1
index b3657264..ff208384 100644
@@ -563,17 +563,17 @@ static gboolean input_event(GIOChannel *source,
 GIOCondition condition,
 	return TRUE;
 }
 
-static void enter_exec_path( char **argv )
+static void enter_exec_path(char **argv)
 {
 	char *exec_path = NULL;
 	char *pos = NULL;

tests/testdisplay.c static gboolean input_event(GIOChannel *source, · line 577

Quoted 10 lines
tests/testdisplay.c +3 -3
 	short len_path = 0;
 	int ret;
 
-	len_path = strlen( argv[0] );
-	exec_path = (char*) malloc(len_path);
+	len_path = strlen(argv[0]);
+	exec_path = (char*) malloc(len_path + 1);
 
-	memcpy(exec_path, argv[0], len_path);
+	memcpy(exec_path, argv[0], len_path + 1);

Ditch all of the above and replace with

	exec_path = strdup(argv[0]);

BR,
Jani.

Quoted 3 lines
tests/testdisplay.c +0 -0
 	pos = strrchr(exec_path, '/');
 	if (pos != NULL)

*(pos+1) = '\0';

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#2 lore raw

Quoting Jani Nikula (2019-03-20 09:26:32)

Quoted 30 lines · Simon
Quoted 29 lines

We need to copy the terminating NULL byte too.

---
 tests/testdisplay.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/testdisplay.c +3 -3
index b3657264..ff208384 100644
@@ -563,17 +563,17 @@ static gboolean input_event(GIOChannel *source,
 GIOCondition condition,
      return TRUE;
 }
 
-static void enter_exec_path( char **argv )
+static void enter_exec_path(char **argv)
 {
      char *exec_path = NULL;
      char *pos = NULL;
      short len_path = 0;
      int ret;
 
-     len_path = strlen( argv[0] );
-     exec_path = (char*) malloc(len_path);
+     len_path = strlen(argv[0]);
+     exec_path = (char*) malloc(len_path + 1);
 
Quoted 10 lines

tests/testdisplay.c static gboolean input_event(GIOChannel *source, · line 577

Quoted 2 lines
tests/testdisplay.c +1 -1
-     memcpy(exec_path, argv[0], len_path);
+     memcpy(exec_path, argv[0], len_path + 1);

Ditch all of the above and replace with

        exec_path = strdup(argv[0]);
Quoted 3 lines
tests/testdisplay.c +0 -0
      pos = strrchr(exec_path, '/');
      if (pos != NULL)
              *(pos+1) = '\0';

And even one step further with dirname(3).
-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev