diff mbox series

discover/user-event: Check for required parameters

Message ID 20180628072135.19937-1-sam@mendozajonas.com
State Accepted
Headers show
Series discover/user-event: Check for required parameters | expand

Commit Message

Sam Mendoza-Jonas June 28, 2018, 7:21 a.m. UTC
Check for some required parameters in the 'dhcp' handler, and in the
'add' handler return an error if parse_user_event() fails rather than
charging ahead into a segfault.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/user-event.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/discover/user-event.c b/discover/user-event.c
index 77d28c1..7f63d43 100644
--- a/discover/user-event.c
+++ b/discover/user-event.c
@@ -390,6 +390,9 @@  static int user_event_dhcp(struct user_event *uev, struct event *event)
 
 	uint8_t hwaddr[MAC_ADDR_SIZE];
 
+	if (!event_get_param(event, "mac") || !event_get_param(event, "ip"))
+		return -1;
+
 	sscanf(event_get_param(event, "mac"),
 	       "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX",
 	       hwaddr, hwaddr + 1, hwaddr + 2,
@@ -411,6 +414,7 @@  static int user_event_add(struct user_event *uev, struct event *event)
 	struct device_handler *handler = uev->handler;
 	struct discover_context *ctx;
 	struct discover_device *dev;
+	int rc;
 
 	/* In case this is a network interface, try to refer to it by UUID */
 	dev = discover_device_create(handler, event_get_param(event, "mac"),
@@ -418,7 +422,11 @@  static int user_event_add(struct user_event *uev, struct event *event)
 	dev->device->id = talloc_strdup(dev, event->device);
 	ctx = device_handler_discover_context_create(handler, dev);
 
-	parse_user_event(ctx, event);
+	rc = parse_user_event(ctx, event);
+	if (rc) {
+		pb_log("parse_user_event returned %d\n", rc);
+		return rc;
+	}
 
 	device_handler_discover_context_commit(handler, ctx);