1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

SQLServer: Don't stat()-then-mkdir() when mkdir() alone is enough

Closes a TOCTOU race that SonarCloud complained about.

SonarCloud: https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVO_uKk92xXUF3qSVc&open=AXuVO_uKk92xXUF3qSVc
This commit is contained in:
Andreas Kling 2021-08-30 17:06:29 +02:00
parent 9fd58fd6d8
commit 4c8fe01bff

View file

@ -18,16 +18,9 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
return 1;
}
struct stat statbuf;
if (stat("/home/anon/sql", &statbuf) != 0) {
if (errno != ENOENT) {
perror("stat");
return 1;
}
if (mkdir("/home/anon/sql", 0700) != 0) {
perror("mkdir");
return 1;
}
if (mkdir("/home/anon/sql", 0700) < 0 && errno != EEXIST) {
perror("mkdir");
return 1;
}
if (unveil("/home/anon/sql", "rwc") < 0) {