Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cookie jar updates should be atomic #4914

Closed
vapier opened this issue Feb 12, 2020 · 2 comments
Closed

cookie jar updates should be atomic #4914

vapier opened this issue Feb 12, 2020 · 2 comments
Assignees

Comments

@vapier
Copy link

vapier commented Feb 12, 2020

I did this

# Create a dummy cookie jar larger than 4KiB.
$ printf '%s\tFALSE\t/\tTRUE\t2147483647\to\tfoo=bar\n' {0..200}.example.com > x

# Run curl reading & writing that cookie jar.
$ strace -e'!signal' curl https://google.com --cookie x --cookie-jar x
...
openat(AT_FDCWD, "x", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
write(4, "# Netscape HTTP Cookie File\n# ht"..., 4096) = 4096
write(4, "e.com\tFALSE\t/\tTRUE\t2147483647\to\t"..., 4096) = 4096
write(4, "LSE\t/\tTRUE\t2147483647\to\tfoo=bar\n"..., 1884) = 1884
close(4)                                = 0
...

I expected the following

other processes accessing the cookie jar should be able to rely on the file being coherent/complete. as it stands, the cookie jar is unreliable with more than one user at a time.

seems like it wouldn't be too difficult to create a tempfile using the name as a base, write to that, then do a single atomic rename.

curl/libcurl version

curl 7.66.0 (x86_64-pc-linux-gnu) libcurl/7.66.0 OpenSSL/1.1.1d zlib/1.2.11 nghttp2/1.39.2

operating system

Linux vapier 5.3.1 #1 SMP PREEMPT Fri Sep 27 00:26:44 EDT 2019 x86_64 AMD FX(tm)-4350 Quad-Core Processor AuthenticAMD GNU/Linux

@bagder bagder added the HTTP label Feb 12, 2020
@bagder
Copy link
Member

bagder commented Feb 12, 2020

It should indeed be possible to create the file with a temp name and then rename it. I would propose we do it by appending a suffix to the actual name.

@jay
Copy link
Member

jay commented Feb 12, 2020

We could use what Mozilla Firefox uses which iirc? is .partfile or .part

bagder added a commit that referenced this issue Feb 14, 2020
Save the file as "[filename].part" and rename away the extension when
done.

Reported-by: Mike Frysinger
Fixes #4914
bagder added a commit that referenced this issue Feb 16, 2020
Save the file as "[filename].part" and rename away the extension when
done.

Co-authored-by: Jay Satiro
Reported-by: Mike Frysinger
Fixes #4914
@bagder bagder self-assigned this Feb 17, 2020
@bagder bagder closed this as completed in b834890 Feb 17, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
@bagder bagder added the cookies label Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

3 participants