[PATCH rtems-libbsd 6-freebsd-12 2/5] rtemsbsd/rtems: Check function return values

Kinsey Moore kinsey.moore at oarcorp.com
Tue Jan 23 21:54:53 UTC 2024


---
 rtemsbsd/rtems/rtems-bsd-rc-conf-net.c | 10 ++++++----
 rtemsbsd/rtems/rtems-bsd-syscall-api.c |  9 ++++++---
 rtemsbsd/rtems/rtems-kernel-init.c     |  4 +++-
 rtemsbsd/rtems/rtems-kernel-pager.c    |  4 +++-
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
index 23ee15db..8ffaa914 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
@@ -103,7 +103,9 @@ cloned_interfaces(rtems_bsd_rc_conf* rc_conf, rtems_bsd_rc_conf_argc_argv* aa)
       "ifconfig", aa->argv[arg], "create", NULL
     };
     rtems_bsd_rc_conf_print_cmd(rc_conf, "cloning_interfaces", 3, ifconfg_args);
-    rtems_bsd_command_ifconfig(3, (char**) ifconfg_args);
+    if (rtems_bsd_command_ifconfig(3, (char**) ifconfg_args)) {
+      return -1;
+    }
   }
 
   return 0;
@@ -377,7 +379,7 @@ defaultrouter(rtems_bsd_rc_conf* rc_conf, rtems_bsd_rc_conf_argc_argv* aa, bool
       memset(&sin, 0, sizeof(sin));
       memset(&rti_info[0], 0, sizeof(rti_info));
       sin.sin_family = AF_INET;
-      inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
+      (void) inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
 
       r = rtems_get_route(&sin, rti_info);
       if (r == 0 && rti_info[RTAX_GATEWAY] != NULL) {
@@ -710,9 +712,9 @@ run_dhcp(rtems_bsd_rc_conf* rc_conf, rtems_bsd_rc_conf_argc_argv* aa)
   }
   dd->config.priority = priority;
 
-  rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
+  r = rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
 
-  if (dd->argc_argv->argc > 0) {
+  if (r == 0 && dd->argc_argv->argc > 0) {
     dd->config.argc = dd->argc_argv->argc;
     dd->config.argv = dd->argc_argv->argv;
   }
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 800aa323..bec03c57 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -1322,9 +1322,12 @@ rtems_bsd_sysgen_vnstat(
 	if (vp == NULL)
 		error = EFAULT;
 	else {
-		VOP_LOCK(vp, LK_SHARED);
-		error = vn_stat(vp, buf, td->td_ucred, NOCRED, td);
-		VOP_UNLOCK(vp, 0);
+		if (VOP_LOCK(vp, LK_SHARED) == 0) {
+			error = vn_stat(vp, buf, td->td_ucred, NOCRED, td);
+			VOP_UNLOCK(vp, 0);
+		} else {
+			error = ENOLCK;
+		}
 	}
 	if (RTEMS_BSD_SYSCALL_TRACE) {
 		printf("bsd: sys: vnstat: exit %p\n", vp);
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c b/rtemsbsd/rtems/rtems-kernel-init.c
index 90a9c809..8ac2f59e 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -223,7 +223,9 @@ rtems_bsd_initialize(void)
 		return RTEMS_UNSATISFIED;
 	}
 
-	mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
+	if (mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
+		return RTEMS_UNSATISFIED;
+	}
 
 	sc = rtems_timer_initiate_server(rtems_bsd_get_task_priority(name),
 	    rtems_bsd_get_task_stack_size(name), RTEMS_DEFAULT_ATTRIBUTES);
diff --git a/rtemsbsd/rtems/rtems-kernel-pager.c b/rtemsbsd/rtems/rtems-kernel-pager.c
index 5a48c2e8..d8febb03 100644
--- a/rtemsbsd/rtems/rtems-kernel-pager.c
+++ b/rtemsbsd/rtems/rtems-kernel-pager.c
@@ -85,7 +85,9 @@ pbuf_ctor(void *mem, int size, void *arg, int flags)
 	bp->b_ioflags = 0;
 	bp->b_iodone = NULL;
 	bp->b_error = 0;
-	BUF_LOCK(bp, LK_EXCLUSIVE, NULL);
+	if (BUF_LOCK(bp, LK_EXCLUSIVE, NULL) != 0) {
+		return -1;
+	}
 
 	return (0);
 }
-- 
2.39.2



More information about the devel mailing list