Re: This is where I'm going with fwcontrol

Dieter <[email protected]>
Newsgroups gmane.os.freebsd.devel.firewire
Message-ID <[email protected]>
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;
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-firewire
To unsubscribe, send any mail to "[email protected]"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.