All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
To: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH i-g-t 1/3] Avoid truncate string in __igt_lsof_fds
Date: Mon, 4 Jun 2018 22:45:27 -0300	[thread overview]
Message-ID: <20180605014527.petnzluv3mz3ccvg@smtp.gmail.com> (raw)
In-Reply-To: <20180604104037.GG16222@ahiler-desk1.ger.corp.intel.com>

Hi Arkadiusz,

First of all, thanks for the review.

I believe that I understood all the comments you made in all of the
patches. I will send the V2 soon.

Thanks!

Best Regards
Rodrigo Siqueira

On 06/04, Arkadiusz Hiler wrote:
> On Tue, May 29, 2018 at 09:46:38PM -0300, Rodrigo Siqueira wrote:
> > Note that 'proc_path' parameter in __igt_lsof_fds receives a string
> > which was initialized with the size of PATH_MAX and the local variable
> > 'path' has the same size, but it also have to append: '/', '\0', and the
> > directory name. This situation caused the warning described below.
> > 
> > warning: ‘%s’ directive output may be truncated writing up to 255 bytes
> > into a region of size between 0 and 4095 [-Wformat-truncation=]
> > snprintf(path, sizeof(path), "%s/%s", proc_path, d->d_name);
> > note: ‘snprintf’ output between 2 and 4352 bytes into a destination of
> > size 4096 [..]
> > 
> > This patch fix the above problem.
> > 
> > Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
> > ---
> >  lib/igt_aux.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/igt_aux.c b/lib/igt_aux.c
> > index acafb713..5dd2761e 100644
> > --- a/lib/igt_aux.c
> > +++ b/lib/igt_aux.c
> > @@ -1425,7 +1425,7 @@ __igt_lsof_fds(proc_t *proc_info, int *state, char *proc_path, const char *dir)
> >  {
> >  	struct dirent *d;
> >  	struct stat st;
> > -	char path[PATH_MAX];
> > +	char path[PATH_MAX + NAME_MAX + 2]; // 1 byte for '/' and another for '\0'
> 
> Hey,
> 
> First of, thanks for looking at the new warnings. We definitely have to
> fix those :-)
> 
> A couple of lines down we have lstat(path, &st), which will return -1
> with errno == ENAMETOOLONG if we go over PATH_MAX, so this does not feel
> right, especially that we are not checking for that.
> 
> Digging deeper, __igt_lsof_fds() is used only inside __igt_lsof(), which
> is the reason for such a high estimate.
> 
> It uses char path[PATH_MAX], which is the main contributing component,
> but it contains at most strlen("/proc/%d/cwd")+1 where "%d" is
> CEILING(LOG_10(INT_MAX)).
> 
> Limiting size of path there to sensible upper estimation should make us
> fit in PATH_MAX in __igt_lsof_fds (or even less).
> 
> -- 
> Cheers,
> Arek
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
To: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: igt-dev@lists.freedesktop.org, gustavo@padovan.org,
	intel-gfx@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/3] Avoid truncate string in __igt_lsof_fds
Date: Mon, 4 Jun 2018 22:45:27 -0300	[thread overview]
Message-ID: <20180605014527.petnzluv3mz3ccvg@smtp.gmail.com> (raw)
In-Reply-To: <20180604104037.GG16222@ahiler-desk1.ger.corp.intel.com>

Hi Arkadiusz,

First of all, thanks for the review.

I believe that I understood all the comments you made in all of the
patches. I will send the V2 soon.

Thanks!

Best Regards
Rodrigo Siqueira

On 06/04, Arkadiusz Hiler wrote:
> On Tue, May 29, 2018 at 09:46:38PM -0300, Rodrigo Siqueira wrote:
> > Note that 'proc_path' parameter in __igt_lsof_fds receives a string
> > which was initialized with the size of PATH_MAX and the local variable
> > 'path' has the same size, but it also have to append: '/', '\0', and the
> > directory name. This situation caused the warning described below.
> > 
> > warning: ‘%s’ directive output may be truncated writing up to 255 bytes
> > into a region of size between 0 and 4095 [-Wformat-truncation=]
> > snprintf(path, sizeof(path), "%s/%s", proc_path, d->d_name);
> > note: ‘snprintf’ output between 2 and 4352 bytes into a destination of
> > size 4096 [..]
> > 
> > This patch fix the above problem.
> > 
> > Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
> > ---
> >  lib/igt_aux.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/igt_aux.c b/lib/igt_aux.c
> > index acafb713..5dd2761e 100644
> > --- a/lib/igt_aux.c
> > +++ b/lib/igt_aux.c
> > @@ -1425,7 +1425,7 @@ __igt_lsof_fds(proc_t *proc_info, int *state, char *proc_path, const char *dir)
> >  {
> >  	struct dirent *d;
> >  	struct stat st;
> > -	char path[PATH_MAX];
> > +	char path[PATH_MAX + NAME_MAX + 2]; // 1 byte for '/' and another for '\0'
> 
> Hey,
> 
> First of, thanks for looking at the new warnings. We definitely have to
> fix those :-)
> 
> A couple of lines down we have lstat(path, &st), which will return -1
> with errno == ENAMETOOLONG if we go over PATH_MAX, so this does not feel
> right, especially that we are not checking for that.
> 
> Digging deeper, __igt_lsof_fds() is used only inside __igt_lsof(), which
> is the reason for such a high estimate.
> 
> It uses char path[PATH_MAX], which is the main contributing component,
> but it contains at most strlen("/proc/%d/cwd")+1 where "%d" is
> CEILING(LOG_10(INT_MAX)).
> 
> Limiting size of path there to sensible upper estimation should make us
> fit in PATH_MAX in __igt_lsof_fds (or even less).
> 
> -- 
> Cheers,
> Arek
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2018-06-05  1:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30  0:46 [PATCH i-g-t 0/3] Fix some GCC warnings Rodrigo Siqueira
2018-05-30  0:46 ` [igt-dev] " Rodrigo Siqueira
2018-05-30  0:46 ` [PATCH i-g-t 1/3] Avoid truncate string in __igt_lsof_fds Rodrigo Siqueira
2018-05-30  0:46   ` [igt-dev] " Rodrigo Siqueira
2018-06-04 10:40   ` Arkadiusz Hiler
2018-06-04 10:40     ` [Intel-gfx] " Arkadiusz Hiler
2018-06-05  1:45     ` Rodrigo Siqueira [this message]
2018-06-05  1:45       ` [igt-dev] " Rodrigo Siqueira
2018-05-30  0:46 ` [PATCH i-g-t 2/3] Remove extra '\0' in strncpy in igt_save_module_param Rodrigo Siqueira
2018-05-30  0:46   ` [igt-dev] " Rodrigo Siqueira
2018-06-04 11:04   ` Arkadiusz Hiler
2018-06-04 11:04     ` [Intel-gfx] " Arkadiusz Hiler
2018-05-30  0:47 ` [PATCH i-g-t 3/3] Move declaration to the top of the code Rodrigo Siqueira
2018-05-30  0:47   ` [igt-dev] " Rodrigo Siqueira
2018-06-04 10:54   ` Arkadiusz Hiler
2018-06-04 10:54     ` [igt-dev] " Arkadiusz Hiler
2018-05-30  2:25 ` [igt-dev] ✓ Fi.CI.BAT: success for Fix some GCC warnings Patchwork
2018-05-30  4:26 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-06-04  8:39 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2018-06-04  9:54 ` [igt-dev] ✓ Fi.CI.IGT: " 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=20180605014527.petnzluv3mz3ccvg@smtp.gmail.com \
    --to=rodrigosiqueiramelo@gmail.com \
    --cc=arkadiusz.hiler@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@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 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.