1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:15:07 +00:00

Kernel: Use try_copy_kstring_from_user() in Socket::setsockopt()

This commit is contained in:
Andreas Kling 2021-08-05 23:10:14 +02:00
parent b96ad76cba
commit 5b13af0edd

View file

@ -108,10 +108,10 @@ KResult Socket::setsockopt(int level, int option, Userspace<const void*> user_va
if (user_value_size != IFNAMSIZ) if (user_value_size != IFNAMSIZ)
return EINVAL; return EINVAL;
auto user_string = static_ptr_cast<const char*>(user_value); auto user_string = static_ptr_cast<const char*>(user_value);
auto ifname = copy_string_from_user(user_string, user_value_size); auto ifname_or_error = try_copy_kstring_from_user(user_string, user_value_size);
if (ifname.is_null()) if (ifname_or_error.is_error())
return EFAULT; return ifname_or_error.error();
auto device = NetworkingManagement::the().lookup_by_name(ifname); auto device = NetworkingManagement::the().lookup_by_name(ifname_or_error.value()->view());
if (!device) if (!device)
return ENODEV; return ENODEV;
m_bound_interface = device; m_bound_interface = device;