mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: Tomas Hozza <thozza@redhat.com>
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
	jasowang@redhat.com, kys@microsoft.com
Subject: Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
Date: Tue, 18 Dec 2012 12:38:03 +0000	[thread overview]
Message-ID: <1355834283.18807.227.camel@deadeye.wl.decadent.org.uk> (raw)
In-Reply-To: <1628506728.5754343.1355817969825.JavaMail.root@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]

On Tue, 2012-12-18 at 03:06 -0500, Tomas Hozza wrote:
> ----- Original Message -----
> > > This is just for sanity. The value PATH_MAX was chosen after
> > > discussion
> > > with K. Y. Srinivasan and Olaf Hering instead of some "magic"
> > > number like
> > > 256 or 512.
> > 
> > PATH_MAX is a magic name.
> 
> It is defined in "limits.h". I would welcome some more constructive
> argumentation and critics.

It still bears no relation to any actual limit in the C library or Linux
kernel.  So it's no more valid than the previous number.

In the current context we're enumerating /sys/class/net and we know that
all the interface names in there are limited to IFNAMSIZ-1 = 15 (there
is also potentially "bonding_masters").  The longest path name we need
to use is definitely much shorter than even 256 bytes.

> > > > Using snprintf() is a good idea, but you need to check the return
> > > > value and handle the truncation case somehow.
> > > 
> > > By using PATH_MAX sized buffer there is no need for handling the
> > > truncation
> > > case.
> >  
> > You are claiming two contradictory things: sprintf() may overrun the
> > buffer, so we need the length check provided by snprintf(), but there
> > is no need to check for truncation because we know the length is
> > sufficient.
> 
> So what do you propose? How should it be solved?

	if (snprintf(dev_id, sizeof(dev_id), ...) >= sizeof(dev_id))
		continue;

Possibly logging a warning.

Ben.

-- 
Ben Hutchings
Life is like a sewer:
what you get out of it depends on what you put into it.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  reply	other threads:[~2012-12-18 12:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09 14:01 [PATCH 1/3] tools/hv: Fix /var subdirectory Tomas Hozza
2012-11-09 14:01 ` [PATCH 2/3] tools/hv: Fix string types Tomas Hozza
2012-11-09 15:56   ` KY Srinivasan
2012-11-09 14:01 ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
2012-11-09 15:52   ` KY Srinivasan
2012-11-09 15:57   ` KY Srinivasan
2012-11-09 15:56 ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
2012-11-12  8:55   ` Tomas Hozza
2012-11-12  8:55     ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
2012-11-26 20:40       ` KY Srinivasan
2012-11-26 20:42     ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
2012-11-26 21:12       ` gregkh
2012-11-26 21:15         ` KY Srinivasan
2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
2012-11-27  7:56             ` [PATCH 2/3] tools/hv: Fix /var subdirectory Tomas Hozza
2012-11-27 13:59               ` KY Srinivasan
2012-11-27  7:56             ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
2012-11-27 13:59               ` KY Srinivasan
2012-11-27 13:58             ` [PATCH 1/3] tools/hv: Fix for long file names from readdir KY Srinivasan
2012-11-27 14:50             ` Ben Hutchings
2012-11-27 20:28               ` Tomas Hozza
2012-11-27 20:41                 ` Ben Hutchings
2012-12-18  8:06                   ` Tomas Hozza
2012-12-18 12:38                     ` Ben Hutchings [this message]
2013-01-17 18:41                       ` Greg KH
2012-11-15 23:38   ` [PATCH 1/3] tools/hv: Fix /var subdirectory gregkh
2012-11-15 23:52     ` KY Srinivasan

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=1355834283.18807.227.camel@deadeye.wl.decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=apw@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    --cc=thozza@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®