From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v3] tests/testdisplay: fix heap overflow
Date: Wed, 20 Mar 2019 13:48:57 +0200 [thread overview]
Message-ID: <20190320114857.5110-1-simon.ser@intel.com> (raw)
v2: also simplify the code by using dirname(3).
v3: dirname may modify in-place its argument, duplicate the string
Signed-off-by: Simon Ser <simon.ser@intel.com>
---
We can't free() the return value of dirname(), because it might be
statically allocated.
Also, we don't want to chdir(NULL).
tests/testdisplay.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index b3657264..67d1b68a 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -51,6 +51,7 @@
#include <cairo.h>
#include <errno.h>
#include <getopt.h>
+#include <libgen.h>
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
@@ -563,24 +564,17 @@ static gboolean input_event(GIOChannel *source, GIOCondition condition,
return TRUE;
}
-static void enter_exec_path( char **argv )
+static void enter_exec_path(const char **argv)
{
- char *exec_path = NULL;
- char *pos = NULL;
- short len_path = 0;
+ char *argv0, *exec_path;
int ret;
- len_path = strlen( argv[0] );
- exec_path = (char*) malloc(len_path);
-
- memcpy(exec_path, argv[0], len_path);
- pos = strrchr(exec_path, '/');
- if (pos != NULL)
- *(pos+1) = '\0';
-
+ argv0 = strdup(argv[0]);
+ igt_assert(argv0);
+ exec_path = dirname(argv0);
ret = chdir(exec_path);
igt_assert_eq(ret, 0);
- free(exec_path);
+ free(argv0);
}
static void restore_termio_mode(int sig)
@@ -626,7 +620,7 @@ int main(int argc, char **argv)
igt_skip_on_simulation();
- enter_exec_path( argv );
+ enter_exec_path((const char **) argv);
while ((c = getopt_long(argc, argv, optstr, long_opts, NULL)) != -1) {
switch (c) {
--
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
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2019-03-20 11:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-20 11:48 Simon Ser [this message]
2019-03-20 12:00 ` [igt-dev] [PATCH i-g-t v3] tests/testdisplay: fix heap overflow Chris Wilson
2019-03-20 12:17 ` Petri Latvala
2019-03-21 10:32 ` Ser, Simon
2019-03-21 10:42 ` Petri Latvala
2019-03-25 11:17 ` Petri Latvala
2019-03-20 13:57 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/testdisplay: fix heap overflow (rev2) Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190320114857.5110-1-simon.ser@intel.com \
--to=simon.ser@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox