summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/rtems/rtems-bsd-rc-conf.c
diff options
context:
space:
mode:
Diffstat (limited to 'rtemsbsd/rtems/rtems-bsd-rc-conf.c')
-rw-r--r--rtemsbsd/rtems/rtems-bsd-rc-conf.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf.c b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
index d559c256..88d98c3e 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
@@ -260,12 +260,14 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
*/
length = strnlen(text, RTEMS_BSD_RC_CONF_MAX_SIZE);
if (length == RTEMS_BSD_RC_CONF_MAX_SIZE) {
+ free(_rc_conf);
errno = E2BIG;
return -1;
}
copy = strdup(text);
if (copy == NULL) {
+ free(_rc_conf);
errno = ENOMEM;
return -1;
}
@@ -286,6 +288,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
lines = malloc(sizeof(char*) * line_count);
if (lines == NULL) {
free(copy);
+ free(_rc_conf);
errno = ENOMEM;
return -1;
}
@@ -335,6 +338,13 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
if (timeout >= 0)
_rc_conf->waiter = rtems_task_self();
+ if (_rc_conf->name == NULL) {
+ free((void*) _rc_conf->lines);
+ free((void*) _rc_conf->data);
+ free(_rc_conf);
+ return -1;
+ }
+
/*
* Create the lock.
*/
@@ -343,6 +353,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
free((void*) _rc_conf->name);
free((void*) _rc_conf->lines);
free((void*) _rc_conf->data);
+ free(_rc_conf);
return -1;
}
@@ -714,6 +725,7 @@ rc_conf_worker(rtems_task_argument task_argument)
rtems_chain_node* node = rtems_chain_first(&services);
int r = 0;
int error;
+ bool rc_conf_verbose;
/*
* Check for a syslog priority before any services are run.
@@ -748,6 +760,8 @@ rc_conf_worker(rtems_task_argument task_argument)
if (r < 0)
rc_conf->error_code = error;
+ rc_conf_verbose = rc_conf->verbose;
+
/*
* If there is a waiter signal else clean up because the waiter has gone.
*/
@@ -760,7 +774,7 @@ rc_conf_worker(rtems_task_argument task_argument)
rc_conf_destroy(rc_conf);
}
- if (rc_conf->verbose)
+ if (rc_conf_verbose)
printf("rc.conf: finished\n");
rtems_task_exit();
@@ -793,6 +807,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
if (sc != RTEMS_SUCCESSFUL) {
fprintf(stderr, "error: %s: get priority: %s\n",
name, rtems_status_text(sc));
+ rc_conf_destroy(rc_conf);
errno = EIO;
return -1;
}
@@ -805,6 +820,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
&worker);
if (sc != RTEMS_SUCCESSFUL) {
fprintf (stderr, "error: worker create: %s", rtems_status_text(sc));
+ rc_conf_destroy(rc_conf);
errno = EIO;
return -1;
}
@@ -814,6 +830,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
(rtems_task_argument) rc_conf);
if (sc != RTEMS_SUCCESSFUL) {
fprintf (stderr, "error: worker start: %s", rtems_status_text(sc));
+ rc_conf_destroy(rc_conf);
errno = EIO;
return - 1;
}
@@ -869,7 +886,7 @@ rtems_bsd_run_rc_conf(const char* name, int timeout, bool verbose)
if (r < 0)
return r;
- rc_conf = malloc(sb.st_size);
+ rc_conf = malloc(sb.st_size + 1);
if (rc_conf == NULL) {
errno = ENOMEM;
return -1;
@@ -892,6 +909,8 @@ rtems_bsd_run_rc_conf(const char* name, int timeout, bool verbose)
fclose(file);
+ rc_conf[sb.st_size] = '\0';
+
r = rtems_bsd_run_rc_conf_script(name, rc_conf, timeout, verbose);
free(rc_conf);