linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] libsocketcan: Initialize stack variables properly
@ 2014-02-07  9:21 Alexander Shiyan
  2014-02-07  9:21 ` [PATCH 2/2] libsocketcan: Remove excess goto's Alexander Shiyan
  2014-02-07  9:40 ` [PATCH 1/2] libsocketcan: Initialize stack variables properly Marc Kleine-Budde
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Shiyan @ 2014-02-07  9:21 UTC (permalink / raw)
  To: linux-can; +Cc: Marc Kleine-Budde, Alexander Shiyan

Stack variables may have unpredictable data if it not initialized.
This patch adds the necessary cleanup stack variables.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 src/libsocketcan.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/libsocketcan.c b/src/libsocketcan.c
index 02714ae..4e7842f 100644
--- a/src/libsocketcan.c
+++ b/src/libsocketcan.c
@@ -705,6 +705,7 @@ int can_do_stop(const char *name)
  */
 int can_do_restart(const char *name)
 {
+	struct req_info req;
 	int err = -1;
 	int state;
 	__u32 restart_ms;
@@ -731,11 +732,10 @@ int can_do_restart(const char *name)
 		goto err_out;
 	}
 
-	struct req_info req_info = {
-		.restart = 1,
-	};
+	memset(&req, 0, sizeof(req));
+	req.restart = 1;
 
-	err = set_link(name, 0, &req_info);
+	err = set_link(name, 0, &req);
 
 err_out:
 	return err;
@@ -758,14 +758,16 @@ err_out:
  */
 int can_set_restart_ms(const char *name, __u32 restart_ms)
 {
-	struct req_info req_info = {
-		.restart_ms = restart_ms,
-	};
+	struct req_info req;
 
-	if (restart_ms == 0)
-		req_info.disable_autorestart = 1;
+	memset(&req, 0, sizeof(req));
+
+	if (restart_ms)
+		req.restart_ms = restart_ms;
+	else
+		req.disable_autorestart = 1;
 
-	return set_link(name, 0, &req_info);
+	return set_link(name, 0, &req);
 }
 
 /**
@@ -822,11 +824,12 @@ int can_set_restart_ms(const char *name, __u32 restart_ms)
 
 int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm)
 {
-	struct req_info req_info = {
-		.ctrlmode = cm,
-	};
+	struct req_info req;
 
-	return set_link(name, 0, &req_info);
+	memset(&req, 0, sizeof(req));
+	req.ctrlmode = cm;
+
+	return set_link(name, 0, &req);
 }
 
 /**
@@ -869,11 +872,12 @@ int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm)
 
 int can_set_bittiming(const char *name, struct can_bittiming *bt)
 {
-	struct req_info req_info = {
-		.bittiming = bt,
-	};
+	struct req_info req;
+
+	memset(&req, 0, sizeof(req));
+	req.bittiming = bt;
 
-	return set_link(name, 0, &req_info);
+	return set_link(name, 0, &req);
 }
 
 /**
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-02-07  9:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-07  9:21 [PATCH 1/2] libsocketcan: Initialize stack variables properly Alexander Shiyan
2014-02-07  9:21 ` [PATCH 2/2] libsocketcan: Remove excess goto's Alexander Shiyan
2014-02-07  9:42   ` Marc Kleine-Budde
2014-02-07  9:40 ` [PATCH 1/2] libsocketcan: Initialize stack variables properly Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).