From d44c6b2de3ebbb78e36491b587817e8cc0aa3652 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Wed, 6 Oct 2010 11:48:35 +0200 Subject: [PATCH] Missing error handling in ctrl_iface_register() ctrl_iface_register() is defined as returning an integer, but doesn't provide any return statement. And the error from eloop_register_read_sock() is completely ignored. References: bnc#644064 Signed-off-by: Hannes Reinecke diff --git a/ctrl_iface.c b/ctrl_iface.c index f55c577..6e7fe77 100644 --- a/ctrl_iface.c +++ b/ctrl_iface.c @@ -407,8 +407,8 @@ static char *ctrl_iface_path(struct clif_data *clifd) int ctrl_iface_register(struct clif_data *clifd) { - eloop_register_read_sock(clifd->ctrl_sock, ctrl_iface_receive, clifd, - NULL); + return eloop_register_read_sock(clifd->ctrl_sock, ctrl_iface_receive, + clifd, NULL); } int ctrl_iface_init(struct clif_data *clifd) diff --git a/eloop.c b/eloop.c index c291977..d354cea 100644 --- a/eloop.c +++ b/eloop.c @@ -84,13 +84,13 @@ static int eloop_sock_table_add_sock(struct eloop_sock_table *table, struct eloop_sock *tmp; if (table == NULL) - return -1; + return -EINVAL; tmp = (struct eloop_sock *) os_realloc(table->table, (table->count + 1) * sizeof(struct eloop_sock)); if (tmp == NULL) - return -1; + return -ENOMEM; tmp[table->count].sock = sock; tmp[table->count].eloop_data = eloop_data; diff --git a/event_iface.c b/event_iface.c index 20af82e..42ff2d5 100644 --- a/event_iface.c +++ b/event_iface.c @@ -278,8 +278,7 @@ int event_iface_init() return -EIO; } - eloop_register_read_sock(fd, event_iface_receive, NULL, NULL); - return 0; + return eloop_register_read_sock(fd, event_iface_receive, NULL, NULL); } int event_iface_deinit() diff --git a/lldpad.c b/lldpad.c index a41f727..9f65c6a 100644 --- a/lldpad.c +++ b/lldpad.c @@ -397,7 +397,13 @@ int main(int argc, char *argv[]) exit(1); } - ctrl_iface_register(clifd); + if (ctrl_iface_register(clifd) < 0) { + if (!daemonize) + fprintf(stderr, "failed to register control interface\n"); + log_message(MSG_ERR_SERVICE_START_FAILURE, + "%s", "failed to register control interface"); + exit(1); + } LLDPAD_WARN("%s is starting", argv[0]); eloop_run();