diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-30 17:06:29 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-30 18:35:36 +0200 |
commit | 4c8fe01bff58694df0bdf50337cea693aaf40681 (patch) | |
tree | 0056983e4a26d7ddc45ed57e6aa40d60ac284233 /Userland/Services/SQLServer | |
parent | 9fd58fd6d862e0c965ee6ec4e47ec2ffe58fd647 (diff) | |
download | serenity-4c8fe01bff58694df0bdf50337cea693aaf40681.zip |
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
Diffstat (limited to 'Userland/Services/SQLServer')
-rw-r--r-- | Userland/Services/SQLServer/main.cpp | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/Userland/Services/SQLServer/main.cpp b/Userland/Services/SQLServer/main.cpp index ac7c4f6610..7c4683a659 100644 --- a/Userland/Services/SQLServer/main.cpp +++ b/Userland/Services/SQLServer/main.cpp @@ -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) { |