Fix coverity defects: CID 147536, 147537, 147538

coverity scan CID:147536, type: Argument cannot be negative
- may write or close fd which is negative
coverity scan CID:147537, type: Argument cannot be negative
- may call dup2 with a negative fd
coverity scan CID:147538, type: Argument cannot be negative
- may read or fchown with a negative fd

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: GeLiXin <ge.lixin@zte.com.cn>
Closes #5185
This commit is contained in:
GeLiXin
2016-10-01 06:40:07 +08:00
committed by Brian Behlendorf
parent 292d573e70
commit ed3ea30fb9
3 changed files with 25 additions and 7 deletions
+12
View File
@@ -94,6 +94,12 @@ main(int argc, char **argv)
int rdret;
int j = 0;
if (fd < 0) {
(void) printf("%s: open <%s> again failed:"
" errno = %d\n", argv[0], dirpath, errno);
exit(-1);
}
while (j < op_num) {
(void) sleep(1);
rdret = read(fd, buf, 16);
@@ -107,6 +113,12 @@ main(int argc, char **argv)
int chownret;
int k = 0;
if (fd < 0) {
(void) printf("%s: open(<%s>, O_RDONLY) again failed:"
" errno (decimal)=%d\n", argv[0], dirpath, errno);
exit(-1);
}
while (k < op_num) {
(void) sleep(1);
chownret = fchown(fd, 0, 0);