cal: Fix race condition between calling stat and opening file
This commit is contained in:
1 parent
f0b8ee117b
commit
87867a5904
1 file changed
+3
-3
@@ -76,14 +76,14 @@ int cal_init_file(const char * file, struct cal ** cal_out) {
|
||||
off_t lsize = 0;
|
||||
#endif
|
||||
|
||||
if ( stat(file, &st) != 0 )
|
||||
return -1;
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
|
||||
if ( fd < 0 )
|
||||
return -1;
|
||||
|
||||
if ( fstat(fd, &st) != 0 )
|
||||
goto err;
|
||||
|
||||
if ( S_ISREG(st.st_mode) )
|
||||
size = st.st_size;
|
||||
else if ( S_ISBLK(st.st_mode) ) {
|
||||
|
||||
Reference in new issue
Block a user