/ Check-in [3426673e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Never leave an open file descriptor pointing into the middle of the database file if the file descriptor number is 2 or less.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | overwrite-avoidance
Files: files | file ages | folders
SHA1: 3426673e4659eb68dbd14a3e41d4620d748432db
User & Date: drh 2013-08-29 21:26:26
Context
2013-08-29
23:34
Change the unix VFS so that it refuses to open a database file using a file descriptor less than 3. Closed-Leaf check-in: 66dddda0 user: drh tags: overwrite-avoidance
21:26
Never leave an open file descriptor pointing into the middle of the database file if the file descriptor number is 2 or less. check-in: 3426673e user: drh tags: overwrite-avoidance
14:56
Restore fix [f15591f802], which was accidentally clobbered by the stat4 merge. check-in: d4b6ad33 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

584
585
586
587
588
589
590

591
592
593
594
595
596
597
....
3129
3130
3131
3132
3133
3134
3135

3136
3137
3138
3139
3140
3141
3142
....
3228
3229
3230
3231
3232
3233
3234

3235
3236
3237
3238
3239
3240
3241
      if( osFstat(fd, &statbuf)==0 
       && statbuf.st_size==0
       && (statbuf.st_mode&0777)!=m 
      ){
        osFchmod(fd, m);
      }
    }

#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
    osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif
  }
  return fd;
}

................................................................................
    }else if( got>0 ){
      cnt -= got;
      offset += got;
      prior += got;
      pBuf = (void*)(got + (char*)pBuf);
    }
  }while( got>0 );

  TIMER_END;
  OSTRACE(("READ    %-3d %5d %7lld %llu\n",
            id->h, got+prior, offset-prior, TIMER_ELAPSED));
  return got+prior;
}

/*
................................................................................
    if( iSeek!=iOff ){
      if( piErrno ) *piErrno = (iSeek==-1 ? errno : 0);
      return -1;
    }
    rc = osWrite(fd, pBuf, nBuf);
  }while( rc<0 && errno==EINTR );
#endif


  TIMER_END;
  OSTRACE(("WRITE   %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED));

  if( rc<0 && piErrno ) *piErrno = errno;
  return rc;
}







>







 







>







 







>







584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
....
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
....
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
      if( osFstat(fd, &statbuf)==0 
       && statbuf.st_size==0
       && (statbuf.st_mode&0777)!=m 
      ){
        osFchmod(fd, m);
      }
    }
    if( fd<=2 ) lseek(fd, 0, SEEK_END);
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
    osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif
  }
  return fd;
}

................................................................................
    }else if( got>0 ){
      cnt -= got;
      offset += got;
      prior += got;
      pBuf = (void*)(got + (char*)pBuf);
    }
  }while( got>0 );
  if( id->h<=2 ) lseek(id->h, 0, SEEK_END);
  TIMER_END;
  OSTRACE(("READ    %-3d %5d %7lld %llu\n",
            id->h, got+prior, offset-prior, TIMER_ELAPSED));
  return got+prior;
}

/*
................................................................................
    if( iSeek!=iOff ){
      if( piErrno ) *piErrno = (iSeek==-1 ? errno : 0);
      return -1;
    }
    rc = osWrite(fd, pBuf, nBuf);
  }while( rc<0 && errno==EINTR );
#endif
  if( fd<=2 ) lseek(fd, 0, SEEK_END);

  TIMER_END;
  OSTRACE(("WRITE   %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED));

  if( rc<0 && piErrno ) *piErrno = errno;
  return rc;
}