Re: [PATCH v5 4/4] mkfs.xfs: add configuration file parsing support using our own parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 11, 2018 at 06:12:01PM -0500, Eric Sandeen wrote:
> Darrick pointed out that this is a TOCTOU race between stat-ing and opening.
> I think it makes more sense to open it, then fstat it, and if it's not ok,
> close it and error out.  LIke this?
> 
> +       fd = openat(AT_FDCWD, cli_config_file, O_NOFOLLOW, O_RDONLY);
> +       if (fd >= 0) {
> +               /* file in CWD or absolute path */
> +               ret = fstat(fd, &st);
> +               if (ret < 0)
> +                       goto out_err;
> +
> +               if (!S_ISREG(st.st_mode)) {
> +                       errno = EINVAL;
> +                       goto out_err;
> +               }
> +
> +               memcpy(*fpath, cli_config_file, strlen(cli_config_file));
> +       } else {

I've addressed this but I put the memcpy() to  in effect if the file opens
as the context above is for CLI and if the CLI was used for a config file
it must exists, otherwise we want to explain which file we used which failed.

For the default it is different, if the default file opens then yes we copy
the name of the default file, however if it does not exists we immediately
bail.

  Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux