Danger: Cargo Clean Removes Everything from the /tmp Directory

This blog post describes what could be an extremely dangerous issue with the default configuration of cargo, the build tool for rust programs. Apparently, the cargo clean command tries to remove everything from its build directory, which defaults to /tmp.

[2021-06-25 13:59:12]:jw@HAL9000-6WQ9TQ2:/mnt/c/temp/cscdprox
$ cargo clean
error: could not remove build directory

Caused by:
  failed to remove file `/tmp/rider/jetbrains-toolbox-1.20.8804/jetbrains-toolbox`

Caused by:
  Permission denied (os error 13)

Luckily, I use /tmp for things that are truly temporary, generally on an instantaneous basis, and some things in /tmp were somehow owned by root, which raised the alert. I do not know what damage this may have done to my system, but honestly I subsequently had issues with WSL that a reboot (luckily) resolved. And Linux programmers chuckle at Windows…

One solution is to specify the target directory on every command path. A safer backup would be to update the target-dir setting in the ~/.cargo/config file from /tmp to something like /tmp/thatsbad A double-failsafe could be to set the CARGO_TARGET_DIR environment variable to something like /tmp/isthatworse.

[2021-06-25 22:21:43]:jw@HAL9000-6WQ9TQ2:~/.cargo
$ grep /tmp ./config
target-dir = "/tmp"

This is obviously not something I had configured.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: