mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
DHCPClient: handle /proc/net/adapters invalid JSON gracefully
This commit is contained in:
parent
ff7dee49f6
commit
2f65363488
Notes:
sideshowbarker
2024-07-18 23:52:27 +09:00
Author: https://github.com/bcoles Commit: https://github.com/SerenityOS/serenity/commit/2f65363488f Pull-request: https://github.com/SerenityOS/serenity/pull/4935 Reviewed-by: https://github.com/linusg
1 changed files with 7 additions and 2 deletions
|
@ -69,13 +69,18 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
|
||||
auto file = Core::File::construct("/proc/net/adapters");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Error: %s\n", file->error_string());
|
||||
warnln("Error: {}", file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto file_contents = file->read_all();
|
||||
auto json = JsonValue::from_string(file_contents);
|
||||
ASSERT(json.has_value());
|
||||
|
||||
if (!json.has_value() || !json.value().is_array()) {
|
||||
warnln("Error: No network adapters available");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Vector<InterfaceDescriptor> ifnames;
|
||||
json.value().as_array().for_each([&ifnames](auto& value) {
|
||||
auto if_object = value.as_object();
|
||||
|
|
Loading…
Add table
Reference in a new issue