Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2008 17:06:30 +0100
From:      Dieter <freebsd@sopwith.solgatos.com>
To:        Sean Bruno <sbruno@miralink.com>
Cc:        Scott Long <scottl@freebsd.org>, freebsd-firewire@freebsd.org
Subject:   Re: This is where I'm going with fwcontrol 
Message-ID:  <200808120006.AAA04467@sopwith.solgatos.com>
In-Reply-To: Your message of "Sat, 09 Aug 2008 13:12:28 PDT." <489DFA2C.4080407@miralink.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
A patch that adds error checking to malloc() and read():

===================================================================
RCS file: RCS/fwcontrol.c,v
retrieving revision 1.2.1.1
diff -u -r1.2.1.1 fwcontrol.c
--- fwcontrol.c	2008/08/11 20:47:34	1.2.1.1
+++ fwcontrol.c	2008/08/12 00:02:37
@@ -188,6 +188,8 @@
 	u_int32_t *qld, res;
 
         asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
+	if (asyreq == NULL)
+	  err(1, "malloc");
 	asyreq->req.len = 16;
 #if 0
 	asyreq->req.type = FWASREQNODE;
@@ -226,6 +228,8 @@
         struct fw_asyreq *asyreq;
 
 	asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
+	if (asyreq == NULL)
+	  err(1, "malloc");
 	asyreq->req.len = 12;
 	asyreq->req.type = FWASREQNODE;
 	asyreq->pkt.mode.ld[0] = 0;
@@ -251,6 +255,8 @@
         struct fw_asyreq *asyreq;
 
 	asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
+	if (asyreq == NULL)
+	  err(1, "malloc");
 	asyreq->req.len = 12;
 	asyreq->req.type = FWASREQNODE;
 	asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
@@ -268,6 +274,8 @@
         struct fw_asyreq *asyreq;
 
 	asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
+	if (asyreq == NULL)
+	  err(1, "malloc");
 	asyreq->req.len = 16;
 	asyreq->req.type = FWASREQNODE;
 	asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f);
@@ -643,7 +651,11 @@
 		err(1, "ioctl FW_SRSTREAM");
 
 	buf = (char *)malloc(1024*16);
+	if (buf == NULL)
+	  err(1, "malloc");
 	len = read(fd, buf, 1024*16);
+	if (len < 0)
+	  err(1, "read");
 	ptr = (u_int32_t *) buf;
 	ciph = (struct ciphdr *)(ptr + 1);
 
@@ -731,6 +743,8 @@
 			break;
 		case 'c':
 			crom_string = malloc(strlen(optarg)+1);
+			if (crom_string == NULL)
+			  err(1, "malloc");
 			strcpy(crom_string, optarg);
 			display_crom = 1;
 			open_needed = 1;
@@ -739,6 +753,8 @@
 			break;
 		case 'd':
 			crom_string_hex = malloc(strlen(optarg)+1);
+			if (crom_string_hex == NULL)
+			  err(1, "malloc");
 			strcpy(crom_string_hex, optarg);
 			display_crom_hex = 1;
 			open_needed = 1;
@@ -827,6 +843,8 @@
 			break;
 		case 'R':
 			recv_data = malloc(strlen(optarg)+1);
+			if (recv_data == NULL)
+			  err(1, "malloc");
 			strcpy(recv_data, optarg);
 			open_needed = 1;
 			command_set = 1;
@@ -834,6 +852,8 @@
 			break;
 		case 'S':
 			send_data = malloc(strlen(optarg)+1);
+			if (send_data == NULL)
+			  err(1, "malloc");
 			strcpy(send_data, optarg);
 			open_needed = 1;
 			display_board_only = 0;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808120006.AAA04467>