Bug 371 - sudo_edit.c mtime checks when source and tmp filesystems have different resolution
sudo_edit.c mtime checks when source and tmp filesystems have different resol...
Status: RESOLVED FIXED
Product: Sudo
Classification: Unclassified
Component: Visudo
1.6.9
PC All
: low normal
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-09-30 01:06 MDT by jrrs
Modified: 2009-10-02 08:38 MDT (History)
1 user (show)

See Also:


Attachments
diff to update stashed copy of mtime based on touched temp file (1.34 KB, patch)
2009-09-30 09:35 MDT, Todd C. Miller
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jrrs 2009-09-30 01:06:55 MDT
---(sudo_edit.c)
        /*
         * If we are unable to set the mtime on the temp file to the value
         * of the original file just make the stashed mtime match the temp
         * file's mtime.  It is better than nothing and we only use the info
         * to determine whether or not a file has been modified.
         */
        if (touch(tfd, NULL, &tf[i].omtim) == -1) {
            if (fstat(tfd, &sb) == 0) {
                tf[i].omtim.tv_sec = mtim_getsec(sb);
                tf[i].omtim.tv_nsec = mtim_getnsec(sb);
            }
            /* XXX - else error? */
        }
---

  if sudoedit is invoked on a filesystem who has different filetime resolution (eg one has nsec resolution one doesn't), as long as touch() succeeds, the result will be that the file is moved into place every time (unless it happens to line up on .000000 seconds in which case they'll naturally be equal).

  take the following from a running copy of sudoedit and its tmpfile, on a linux host where the tmp filesystem (ext3) does not offer nsec resolution, but the source filesystem (netapp nfs) does:

---
#linux 0918_02:27:36 $ stat myass /var/tmp/myass.XXYWIq4X                
  File: `myass'                                                                                                   
  Size: 0               Blocks: 0          IO Block: 65536  regular empty file        
Device: 15h/21d Inode: 3279889     Links: 1                                           
Access: (0644/-rw-r--r--)  Uid: (  645/    jrrs)   Gid: (  645/    jrrs)              
Access: 2009-09-18 02:23:28.325745000 -0400
Modify: 2009-09-18 02:23:28.325745000 -0400
Change: 2009-09-18 02:23:28.325745000 -0400                               
  File: `/var/tmp/myass.XXYWIq4X'                                         
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 807h/2055d      Inode: 30          Links: 1
Access: (0600/-rw-------)  Uid: (  645/    jrrs)   Gid: (  645/    jrrs)
Access: 2009-09-18 02:27:34.000000000 -0400
Modify: 2009-09-18 02:23:28.000000000 -0400
Change: 2009-09-18 02:27:34.000000000 -0400
---
Comment 1 jrrs 2009-09-30 01:20:36 MDT
btw trackdown credits go to Philippe Levan <levan@epix.net>
Comment 2 Todd C. Miller 2009-09-30 09:35:34 MDT
Created attachment 264 [details]
diff to update stashed copy of mtime based on touched temp file

Please try the attached diff, it should fix the issue.
Comment 3 jrrs 2009-10-01 20:02:02 MDT
(In reply to comment #2)
> Created an attachment (id=264) [details]
> diff to update stashed copy of mtime based on touched temp file
> 
> Please try the attached diff, it should fix the issue.

verified the diff works - no longer always moves the file into place.