Skip to content

Commit

Permalink
Merge pull request #468 from ramsayleung/ramsay/fix-suspicious_open_o…
Browse files Browse the repository at this point in the history
…ptions

[fix] the suspicious use of OpenOptions::create() without an explicit OpenOptions::truncate().
  • Loading branch information
ramsayleung authored Mar 24, 2024
2 parents c1cda7e + cb1965c commit 63c3bba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rspotify-model/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ impl Token {
pub fn write_cache<T: AsRef<Path>>(&self, path: T) -> ModelResult<()> {
let token_info = serde_json::to_string(&self)?;

let mut file = fs::OpenOptions::new().write(true).create(true).open(path)?;
let mut file = fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(path)?;
file.set_len(0)?;
file.write_all(token_info.as_bytes())?;

Expand Down

0 comments on commit 63c3bba

Please sign in to comment.