NetBSD-Bugs archive

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

Re: bin/55815: tar opens device files



> On Jun 5, 2021, at 6:17 AM, Christos Zoulas <christos%zoulas.com@localhost> wrote:
> 
> Well, if you want to avoid TOCTOA, you need something like linux's O_PATH
> which opens the file for "stat" like access only. But even linux does not have
> a way to "upgrade" that fd to be able to read, short of:
> 
> fd = open(path, O_PATH);
> fstat(fd, &st);
> if (is a device)
> 	bail;
> snprintf(buf, sizeof(buf), "/proc/self/fds/%d", fd);
> nfd = open(buf, O_RDONLY);
> 
> We do have O_EXEC, but I am not sure if that is the same as O_PATH (if it
> does not really open the device)

If we’re talking about “ensure the file we’re opening is a regular file”, won’t O_REGULAR do that you want?

-- thorpej



Home | Main Index | Thread Index | Old Index