From 7c5a2487c160cab167aa730ae03364ed1a275d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 6 Jan 2010 17:53:03 +0000 Subject: [PATCH] Patch by Andreas Faerber: * Fixed coding style issues pointed out by Axel. * Fixed potential buffer overflow and fault in default-client-up code path (OF counts terminating zero char, too). * Added an intermediate fallback to parsing the boot path * Added himself to the copyright holders Thanks a lot! Fixes ticket #5189. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34918 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../boot/platform/openfirmware/network.cpp | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/system/boot/platform/openfirmware/network.cpp b/src/system/boot/platform/openfirmware/network.cpp index 0323546b23..5ae82d260a 100644 --- a/src/system/boot/platform/openfirmware/network.cpp +++ b/src/system/boot/platform/openfirmware/network.cpp @@ -1,5 +1,6 @@ /* * Copyright 2005, Ingo Weinhold . + * Copyright 2010, Andreas Faerber * All rights reserved. Distributed under the terms of the MIT License. */ @@ -31,7 +32,7 @@ public: OFEthernetInterface(); virtual ~OFEthernetInterface(); - status_t Init(const char *device); + status_t Init(const char *device, const char *parameters); virtual mac_addr_t MACAddress() const; @@ -117,7 +118,7 @@ OFEthernetInterface::~OFEthernetInterface() status_t -OFEthernetInterface::Init(const char *device) +OFEthernetInterface::Init(const char *device, const char *parameters) { if (!device) return B_BAD_VALUE; @@ -160,16 +161,24 @@ OFEthernetInterface::Init(const char *device) if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) { SetIPAddress(ntohl(dhcpResponse.ip_address)); } else { - char saddr[16]; - package = of_finddevice("/options"); - bytesRead = of_getprop(package, "default-client-ip", saddr, - sizeof(saddr)); - if (bytesRead != OF_FAILED) { - saddr[bytesRead] = '\0'; - printf("default-client-ip: %s\n", saddr); - ip_addr_t addr = parse_ip_address(saddr); - printf("addr = %x\n", (unsigned int)addr); - SetIPAddress(addr); + // try to read manual client IP from boot path + if (parameters != NULL) { + char *comma = strrchr(parameters, ','); + if (comma != NULL && comma != strchr(parameters, ',')) { + SetIPAddress(parse_ip_address(comma + 1)); + } + } + if (fIPAddress == 0) { + // try to read default-client-ip setting + char defaultClientIP[16]; + package = of_finddevice("/options"); + bytesRead = of_getprop(package, "default-client-ip", + defaultClientIP, sizeof(defaultClientIP) - 1); + if (bytesRead != OF_FAILED && bytesRead > 1) { + defaultClientIP[bytesRead] = '\0'; + ip_addr_t address = parse_ip_address(defaultClientIP); + SetIPAddress(address); + } } } @@ -278,7 +287,7 @@ platform_net_stack_init() if (!interface) return B_NO_MEMORY; - status_t error = interface->Init(bootPath); + status_t error = interface->Init(bootPath, parameters + 1); if (error != B_OK) { delete interface; return error;