John,

Just to be clear: fastpath is for serving static content. This is not
what you are doing here, you are creating a temporary file to store
dynamic content. For your bug to work you must delete the old file and
create a new one within the same second, etc. 

Also, your code sequence below will leave temporary files around in the
case of a crash. If you want to safely serve the content from this
temporary storage, you should unlink after you finish creating it (no
other thread or process will be able to access the content, or you can
unlink before you write the content and even local users will not be
able to see the file. 

Then just send out the contents directly using the fd not the file
name.  

(maybe something like:

ns_return 200 [ns_guesstype $myfile] [read $fd]

Then you can close the fd, although AOLserver does that automatically at
the end of each request.

Now: why are you writing the content to disk? Can't you use a temp
variable.

tom jackson


On Mon, 2008-08-18 at 14:13 -0700, John Caruso wrote:
> On Monday 01:33 PM 8/18/2008, Tom Jackson wrote:
> >It's not be a data corruption issue
> >because you are choosing to overwrite the old data with new data using
> >the exact same file name. If the data is important, don't overwrite it,
> >thus no corruption.
> 
> No, you've misunderstood the scenario.  The file name needn't be the same 
> to trigger this issue, and the "corruption" doesn't come from serving data 
> out of a file that's changing, but rather because fastpath caching 
> mistakenly identifies a new file as being identical to a previously-cached 
> file (for the reasons I outlined) and erroneously serves the 
> previously-cached data to the user.
> 
> This is a design limitation and arguably a bug in the fastpath caching 
> implementation, which is potentially quite serious since it silently 
> serves the wrong data to the user.  If you want a more straightforward 
> (albeit contrived) demonstration of the problem, here you go:
> 
>     set file [open "/var/tmp/myfile" "w"]
>     puts $file "ABC123"
>     close $file
>     ns_returnfile 200 text/plain "/var/tmp/myfile"
>     ns_unlink -nocomplain "/var/tmp/myfile"
> 
>     set file [open "/var/tmp/myotherfile" "w"]
>     puts $file "XYZ987"
>     close $file
>     ns_returnfile 200 text/plain "/var/tmp/myotherfile"
>     ns_unlink -nocomplain "/var/tmp/myotherfile"
> 
> Assuming that /var/tmp/myfile and /var/tmp/myotherfile are created within 
> the same second, the fastpath caching algorithm will misidentify them as 
> the same file, and ns_returnfile will therefore erroneously return the 
> (previously cached) contents of /var/tmp/myfile when it should be 
> returning the (uncached) contents of /var/tmp/myotherfile.
> 
> - John
> 
> 
> --
> AOLserver - http://www.aolserver.com/
> 
> To Remove yourself from this list, simply send an email to <[EMAIL 
> PROTECTED]> with the
> body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
> field of your email blank.
> 


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to