diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2017-01-08 14:33:08 +0100 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2017-01-08 14:33:08 +0100 |
commit | 87867a590479c9cbd6dcff6d6ed40b6981102ee0 (patch) | |
tree | dc0d28cfd0cfe368ae45e2b501a8d46fdffde040 | |
parent | f0b8ee117b33f9202a36647903a3753e7609ee8b (diff) | |
download | 0xFFFF-87867a590479c9cbd6dcff6d6ed40b6981102ee0.tar.bz2 |
cal: Fix race condition between calling stat and opening file
-rw-r--r-- | src/cal.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -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) ) { |