All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Simon Ser <simon.ser@intel.com>, igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/3] tests/testdisplay: fix heap overflow
Date: Wed, 20 Mar 2019 11:22:06 +0000	[thread overview]
Message-ID: <155308092658.8718.11106976676851152585@skylake-alporthouse-com> (raw)
In-Reply-To: <20190320111556.2476-1-simon.ser@intel.com>

Quoting Simon Ser (2019-03-20 11:15:54)
> Also simplify the code by using dirname(3).
> 
> Signed-off-by: Simon Ser <simon.ser@intel.com>
> ---
>  tests/testdisplay.c | 17 ++++-------------
>  1 file changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index b3657264..2b26ed1b 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,14 @@ 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;
> +       char *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';
> -
> +       exec_path = dirname(argv[0]);

dirname() modifies inplace, so it might not be suitable as presumably we
were copying the argv[0] for a reason :)

exec_path = strcpy(argv[0]);
if (exec_path)
	exec_path = dirname(exec_path);
igt_assert_eq(chdir(exec_path), 0);
free(exec_path);

And if we are not allowed to modify argv, why not say so and make it
const?
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-03-20 11:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-20 11:15 [igt-dev] [PATCH i-g-t 1/3] tests/testdisplay: fix heap overflow Simon Ser
2019-03-20 11:15 ` [igt-dev] [PATCH i-g-t 2/3] meson: add -Wno-missing-braces Simon Ser
2019-03-20 11:15 ` [igt-dev] [PATCH i-g-t 3/3] runner/executor: refactor error handling Simon Ser
2019-03-20 11:18 ` [igt-dev] [PATCH i-g-t 1/3] tests/testdisplay: fix heap overflow Ser, Simon
2019-03-20 11:22 ` Chris Wilson [this message]
2019-03-20 11:29   ` Ser, Simon
2019-03-20 13:01 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/3] " 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=155308092658.8718.11106976676851152585@skylake-alporthouse-com \
    --to=chris@chris-wilson.co.uk \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=simon.ser@intel.com \
    /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 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.