GNU bug report logs - #11761
Slight bug in split :-)

Previous Next

Package: coreutils;

Reported by: Jim Meyering <jim <at> meyering.net>

Date: Thu, 21 Jun 2012 22:16:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #17 received at 11761-done <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: François Pinard <pinard <at> iro.umontreal.ca>,
	11761-done <at> debbugs.gnu.org
Subject: Re: bug#11761: Slight bug in split :-)
Date: Fri, 22 Jun 2012 11:26:09 +0200
Pádraig Brady wrote:
> I'll push the attached in a while.
...
> @@ -360,10 +363,25 @@ create (const char *name)
>  {
>    if (!filter_command)
>      {
> +      int fd;
> +      struct stat out_stat_buf;
> +
>        if (verbose)
>          fprintf (stdout, _("creating file %s\n"), quote (name));
> -      return open (name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
> -                   (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
> +
> +      fd = open (name, O_WRONLY | O_CREAT | O_BINARY,
> +                 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
> +      if (fd < 0)
> +        return fd;
> +      if (fstat (fd, &out_stat_buf) != 0)
> +        error (EXIT_FAILURE, errno, _("failed to stat %s"), quote (name));
> +      if (SAME_INODE (in_stat_buf, out_stat_buf))
> +        error (EXIT_FAILURE, 0, _("%s would overwrite input; aborting"),
> +               quote (name));
> +      if (ftruncate (fd, 0) != 0)
> +        error (EXIT_FAILURE, errno, _("%s: error truncating"), quote (name));
> +
> +      return fd;

Thanks.
That looks fine and passes "make check syntax-check" (no surprise).
Please move the declaration of "fd" down to the point of initialization.

That would induce a line-split, but perhaps this is a good excuse to
factor out these:  (maybe name it something like MODE_RW_UGO)

    $ git grep -l 'S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH'
    src/dd.c
    src/mkfifo.c
    src/mknod.c
    src/split.c
    src/touch.c
    src/truncate.c




This bug report was last modified 13 years and 22 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.