Bug? "fstat64(f, ) < 0 && S_ISREG(sb.st_mode)"

2016-10-25 Thread Denys Vlasenko
/* Take care of noclobber mode. */ if (Cflag) { fname = redir->nfile.expfname; if (stat64(fname, ) < 0) { if ((f = open64(fname, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0)

Re: Bug? "fstat64(f, ) < 0 && S_ISREG(sb.st_mode)"

2016-10-25 Thread Eduardo Bustamante
Also, inspecting bash code, this seems to be code to figure out if the file was changed from a non-regular file to a regular file between the stat and the open, so I'd say it's indeed a bug, but the problem is not the &&, but testing the wrong return code. >From bash redir.c 631 /* OK, the

Re: Bug? "fstat64(f, ) < 0 && S_ISREG(sb.st_mode)"

2016-10-25 Thread Eduardo Bustamante
I see the change was introduced here http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=f78674ed6f95b594dcac0e96d6a76c5f64aa2cbf, by importing code from FreeBSD's sh. What I find interesting is testing the contents of 'sb', when the fstat64 call failed. FreeBSD's code has the opposite: