1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:07:44 +00:00

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.
This commit is contained in:
Emanuele Torre 2020-06-21 09:54:07 +02:00 committed by GitHub
parent 8edecbea4b
commit 4bbe01def1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()) {