diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2020-06-21 09:54:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 09:54:07 +0200 |
commit | 4bbe01def134e991abd2c96aa7eac2add7ef1f2b (patch) | |
tree | fe3ef638f4797f42b5bbd0c155566786107fc4fa /Userland/chown.cpp | |
parent | 8edecbea4b1a9839419d3549b181ea2ca0071a60 (diff) | |
download | serenity-4bbe01def134e991abd2c96aa7eac2add7ef1f2b.zip |
chown: Don't allow "invalid" uid/gid specs (#2596)
The usage message states that a uid/gid spec should be <uid[:gid]>.
Let's not allow `anon:`, `anon:users:hello` and `:users` then.
Diffstat (limited to 'Userland/chown.cpp')
-rw-r--r-- | Userland/chown.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/chown.cpp b/Userland/chown.cpp index 0dba8b7f74..6e5040380b 100644 --- a/Userland/chown.cpp +++ b/Userland/chown.cpp @@ -48,11 +48,15 @@ int main(int argc, char** argv) uid_t new_uid = -1; gid_t new_gid = -1; - auto parts = String(argv[1]).split(':'); + auto parts = String(argv[1]).split(':', true); if (parts.is_empty()) { fprintf(stderr, "Empty uid/gid spec\n"); return 1; } + if (parts[0].is_empty() || (parts.size() == 2 && parts[1].is_empty()) || parts.size() > 2) { + fprintf(stderr, "Invalid uid/gid spec\n"); + return 1; + } auto number = parts[0].to_uint(); if (number.has_value()) { |