bug: mkdir_r uses strtok() which is not thread-safe #35
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In
src/shared/utils.c:29,mkdir_r()usesstrtok()to split the path into components:strtok()uses a hidden static buffer and is not thread-safe. If two threads callmkdir_r()simultaneously (e.g., during multithreaded file writing on the server), the paths will be interleaved and corrupted.Additionally,
strtok()modifies the input string in-place (which is why it takeschar*notconst char*), but the code already makes a duplicate for this purpose.Fix: Replace
strtok()withstrtok_r()(the reentrant version) or manually parse the string character-by-character.Location:
src/shared/utils.c:29Severity: high