mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +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:
parent
8edecbea4b
commit
4bbe01def1
1 changed files with 5 additions and 1 deletions
|
@ -48,11 +48,15 @@ int main(int argc, char** argv)
|
||||||
uid_t new_uid = -1;
|
uid_t new_uid = -1;
|
||||||
gid_t new_gid = -1;
|
gid_t new_gid = -1;
|
||||||
|
|
||||||
auto parts = String(argv[1]).split(':');
|
auto parts = String(argv[1]).split(':', true);
|
||||||
if (parts.is_empty()) {
|
if (parts.is_empty()) {
|
||||||
fprintf(stderr, "Empty uid/gid spec\n");
|
fprintf(stderr, "Empty uid/gid spec\n");
|
||||||
return 1;
|
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();
|
auto number = parts[0].to_uint();
|
||||||
if (number.has_value()) {
|
if (number.has_value()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue