From owner-freebsd-firewire@FreeBSD.ORG Tue Aug 12 00:07:35 2008 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 889D9106567D; Tue, 12 Aug 2008 00:07:35 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from parsely.rain.com (parsely.rain.com [199.26.172.196]) by mx1.freebsd.org (Postfix) with ESMTP id D1C748FC18; Tue, 12 Aug 2008 00:07:34 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from sopwith.solgatos.com (uucp@localhost) by parsely.rain.com (8.11.4/8.11.4) with UUCP id m7C07U831733; Mon, 11 Aug 2008 17:07:30 -0700 (PDT) (envelope-from freebsd@sopwith.solgatos.com) Received: from localhost by sopwith.solgatos.com (8.8.8/6.24) id AAA04467; Tue, 12 Aug 2008 00:06:30 GMT Message-Id: <200808120006.AAA04467@sopwith.solgatos.com> To: Sean Bruno In-reply-to: Your message of "Sat, 09 Aug 2008 13:12:28 PDT." <489DFA2C.4080407@miralink.com> Date: Mon, 11 Aug 2008 17:06:30 +0100 From: Dieter Cc: Scott Long , freebsd-firewire@freebsd.org Subject: Re: This is where I'm going with fwcontrol X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2008 00:07:35 -0000 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;