All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 14/16] tailf: ensure file argument really is a file
Date: Tue, 24 Feb 2015 13:18:00 +0100	[thread overview]
Message-ID: <20150224121800.GO19430@ws.net.home> (raw)
In-Reply-To: <1424616106-580-15-git-send-email-kerolasa@iki.fi>

On Sun, Feb 22, 2015 at 02:41:44PM +0000, Sami Kerola wrote:
>  text-utils/tailf.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/text-utils/tailf.c b/text-utils/tailf.c
> index d856203..7f053a4 100644
> --- a/text-utils/tailf.c
> +++ b/text-utils/tailf.c
> @@ -233,6 +233,28 @@ static long old_style_option(int *argc, char **argv, unsigned long *lines)
>  	return ret;
>  }
>  
> +static int is_file(const char *filename, const struct stat sb)
> +{
> +	switch (sb.st_mode & S_IFMT) {
> +	case S_IFREG:
> +		return 0;
> +	case S_IFLNK:
> +		{
> +			char *resolved_path = NULL;
> +			struct stat follow;
> +			int ret;
> +
> +			if (realpath(filename, resolved_path)) {
> +				stat(resolved_path, &follow);
> +				ret = is_file(resolved_path, follow);
> +				free(resolved_path);
> +				return ret;
> +			}
> +		}

 but you use stat() and no lstat(), so you don't have to care about
 symlinks, right? :-)

>  	if (stat(filename, &old) != 0)
>  		err(EXIT_FAILURE, _("stat of %s failed"), filename);

 if (IS_REG(old.st_mode))
        errx(EXIT_FAILURE, _("%s: is not a file"), filename);

> +	if (is_file(filename, old))
> +		errx(EXIT_FAILURE, _("%s: is not a file"), filename);
>  	if (lines && old.st_size)
>  		tailf(filename, lines, &old);

   Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  reply	other threads:[~2015-02-24 12:18 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-22 14:41 [PATCH 00/16] pull: changes to various utils Sami Kerola
2015-02-22 14:41 ` [PATCH 01/16] whereis: tell when mandatory option is missing Sami Kerola
2015-02-22 17:37   ` Benno Schulenberg
2015-02-24  9:40   ` Karel Zak
2015-03-01 11:08     ` Sami Kerola
2015-03-03 11:32       ` Karel Zak
2015-03-03 12:59         ` Sami Kerola
2015-03-03 23:07           ` Sami Kerola
2015-02-22 14:41 ` [PATCH 02/16] flock: add --verbose option Sami Kerola
2015-02-22 17:44   ` Benno Schulenberg
2015-03-01 11:11     ` Sami Kerola
2015-02-22 14:41 ` [PATCH 03/16] flock: improve timeout handling Sami Kerola
2015-02-24 10:21   ` Karel Zak
2015-03-01 11:46     ` Sami Kerola
2015-03-02  9:13       ` Karel Zak
2015-03-05  9:36   ` Karel Zak
2015-02-22 14:41 ` [PATCH 04/16] prlimit: tell in --verbose output which pid got the new limit Sami Kerola
2015-02-24 10:25   ` Karel Zak
2015-02-22 14:41 ` [PATCH 05/16] tunelp: remove get_val() in favour of strtol_or_err() Sami Kerola
2015-02-24 10:29   ` Karel Zak
2015-02-22 14:41 ` [PATCH 06/16] tunelp: remove unnecessary preprocessor directives Sami Kerola
2015-02-22 14:41 ` [PATCH 07/16] lib/strutils: move parse_switch() from setterm(1) to library Sami Kerola
2015-02-22 17:12   ` Benno Schulenberg
2015-02-24 10:34   ` Karel Zak
2015-02-22 14:41 ` [PATCH 08/16] tunelp: use parse_switch() Sami Kerola
2015-02-24 10:40   ` Karel Zak
2015-02-22 14:41 ` [PATCH 09/16] eject: " Sami Kerola
2015-02-24 11:37   ` Karel Zak
2015-03-01 11:49     ` Sami Kerola
2015-02-22 14:41 ` [PATCH 10/16] rpmatch: use symbolic value when evaluation return codes Sami Kerola
2015-02-24 11:47   ` Karel Zak
2015-02-22 14:41 ` [PATCH 11/16] tailf: check printing criteria more carefully Sami Kerola
2015-02-24 11:53   ` Karel Zak
2015-03-01 11:55     ` Sami Kerola
2015-02-22 14:41 ` [PATCH 12/16] tailf: count last lines correctly at initial print out Sami Kerola
2015-02-24 12:12   ` Karel Zak
2015-03-01 12:09     ` Sami Kerola
2015-02-22 14:41 ` [PATCH 13/16] tailf: do not allow minus signed last lines argument Sami Kerola
2015-02-22 14:41 ` [PATCH 14/16] tailf: ensure file argument really is a file Sami Kerola
2015-02-24 12:18   ` Karel Zak [this message]
2015-03-01 12:20     ` Sami Kerola
2015-02-22 14:41 ` [PATCH 15/16] logger: move /dev/log to pathnames.h Sami Kerola
2015-02-24 12:19   ` Karel Zak
2015-02-22 14:41 ` [PATCH 16/16] logger: fix -i argument parsing regression Sami Kerola
2015-02-22 17:21   ` Benno Schulenberg
2015-03-01 11:06     ` Sami Kerola
2015-02-22 17:10 ` [PATCH 11/62] pull: Benno Schulenberg
2015-03-05 10:16 ` [PATCH 00/16] pull: changes to various utils Karel Zak

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=20150224121800.GO19430@ws.net.home \
    --to=kzak@redhat.com \
    --cc=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.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.