Don't write an empty timestamp record when timestamp_timeout is

zero.  If we find an empty record in the timestamp file, overwrite
it with a good one, truncating the file as needed.
This commit is contained in:
Todd C. Miller
2014-03-17 07:14:55 -06:00
parent 60cf68ad16
commit 4d712aa903

View File

@@ -119,11 +119,13 @@ ts_find_record(int fd, struct timestamp_entry *key, struct timestamp_entry *entr
*/
while (read(fd, &cur, sizeof(cur)) == sizeof(cur)) {
if (cur.size != sizeof(cur)) {
/* wrong size, seek to next record */
/* wrong size, seek to start of next record */
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
"wrong sized record, got %hu, expected %zu",
cur.size, sizeof(cur));
lseek(fd, (off_t)cur.size - (off_t)sizeof(cur), SEEK_CUR);
if (cur.size == 0)
break; /* size must be non-zero */
continue;
}
if (ts_match_record(key, &cur)) {
@@ -327,6 +329,10 @@ update_timestamp(struct passwd *pw)
int fd;
debug_decl(update_timestamp, SUDO_DEBUG_AUTH)
/* Zero timeout means don't update the time stamp file. */
if (def_timestamp_timeout == 0)
goto done;
/* Check/create parent directories as needed. */
if (!ts_secure_dir(def_timestampdir, true, false))
goto done;