From owner-svn-src-all@freebsd.org Fri Jan 20 21:21:43 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 96102CBA32E; Fri, 20 Jan 2017 21:21:43 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 56FD3115F; Fri, 20 Jan 2017 21:21:43 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v0KLLgRx046867; Fri, 20 Jan 2017 21:21:42 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0KLLgm0046863; Fri, 20 Jan 2017 21:21:42 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201701202121.v0KLLgm0046863@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Fri, 20 Jan 2017 21:21:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r312558 - head/sbin/camcontrol X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2017 21:21:43 -0000 Author: asomers Date: Fri Jan 20 21:21:41 2017 New Revision: 312558 URL: https://svnweb.freebsd.org/changeset/base/312558 Log: Misc Coverity fixes in camcontrol(8) CID 1229913 Fix output of "camcontrol persist -i report_capabilities". The reported Persistent Reservation Types were wrong in all cases. CID 1356029 Annotate the code so Coverity will know that this is a false positive. CID 1366830 Fix a memory leak in "camcontrol timestamp -s" CID 1366832 Fix a segfault that could be caused by bad drive firmware Also, fix the man page entry for the "camcontrol epc state" command to match what the code does. Reviewed by: ken, wblock MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D9239 Modified: head/sbin/camcontrol/camcontrol.8 head/sbin/camcontrol/epc.c head/sbin/camcontrol/persist.c head/sbin/camcontrol/timestamp.c Modified: head/sbin/camcontrol/camcontrol.8 ============================================================================== --- head/sbin/camcontrol/camcontrol.8 Fri Jan 20 21:15:22 2017 (r312557) +++ head/sbin/camcontrol/camcontrol.8 Fri Jan 20 21:21:41 2017 (r312558) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 15, 2017 +.Dd January 20, 2017 .Dt CAMCONTROL 8 .Os .Sh NAME @@ -2374,6 +2374,20 @@ this power condition will be affected. .It state Enable or disable a particular power condition. .Bl -tag -width 7n +.It Fl e +Enable the power condition. +One of +.Fl e +or +.Fl d +is required. +.It Fl d +Disable the power condition. +One of +.Fl d +or +.Fl e +is required. .It Fl p Ar cond Specify the power condition: Idle_a, Idle_b, Idle_c, Standby_y, Standby_z. This argument is required. Modified: head/sbin/camcontrol/epc.c ============================================================================== --- head/sbin/camcontrol/epc.c Fri Jan 20 21:15:22 2017 (r312557) +++ head/sbin/camcontrol/epc.c Fri Jan 20 21:21:41 2017 (r312558) @@ -783,6 +783,7 @@ epc(struct cam_device *device, int argc, warnx("Must specify a timer value (-T time)"); error = 1; } + /* FALLTHROUGH */ case ATA_SF_EPC_SET_STATE: if (enable == -1) { warnx("Must specify enable (-e) or disable (-d)"); Modified: head/sbin/camcontrol/persist.c ============================================================================== --- head/sbin/camcontrol/persist.c Fri Jan 20 21:15:22 2017 (r312557) +++ head/sbin/camcontrol/persist.c Fri Jan 20 21:21:41 2017 (r312558) @@ -241,9 +241,11 @@ persist_print_cap(struct scsi_per_res_ca { uint32_t length; int check_type_mask = 0; + uint32_t type_mask; length = scsi_2btoul(cap->length); length = MIN(length, valid_len); + type_mask = scsi_2btoul(cap->type_mask); if (length < __offsetof(struct scsi_per_res_cap, type_mask)) { fprintf(stdout, "Insufficient data (%u bytes) to report " @@ -345,20 +347,20 @@ persist_print_cap(struct scsi_per_res_ca fprintf(stdout, "Supported Persistent Reservation Types:\n"); fprintf(stdout, " Write Exclusive - All Registrants " "(WR_EX_AR): %d\n", - (cap->type_mask[0] & SPRI_TM_WR_EX_AR)? 1 : 0); + (type_mask & SPRI_TM_WR_EX_AR)? 1 : 0); fprintf(stdout, " Exclusive Access - Registrants Only " "(EX_AC_RO): %d\n", - (cap->type_mask[0] & SPRI_TM_EX_AC_RO) ? 1 : 0); + (type_mask & SPRI_TM_EX_AC_RO) ? 1 : 0); fprintf(stdout, " Write Exclusive - Registrants Only " "(WR_EX_RO): %d\n", - (cap->type_mask[0] & SPRI_TM_WR_EX_RO)? 1 : 0); + (type_mask & SPRI_TM_WR_EX_RO)? 1 : 0); fprintf(stdout, " Exclusive Access (EX_AC): %d\n", - (cap->type_mask[0] & SPRI_TM_EX_AC) ? 1 : 0); + (type_mask & SPRI_TM_EX_AC) ? 1 : 0); fprintf(stdout, " Write Exclusive (WR_EX): %d\n", - (cap->type_mask[0] & SPRI_TM_WR_EX) ? 1 : 0); + (type_mask & SPRI_TM_WR_EX) ? 1 : 0); fprintf(stdout, " Exclusive Access - All Registrants " "(EX_AC_AR): %d\n", - (cap->type_mask[1] & SPRI_TM_EX_AC_AR) ? 1 : 0); + (type_mask & SPRI_TM_EX_AC_AR) ? 1 : 0); } else { fprintf(stdout, "Persistent Reservation Type Mask is NOT " "valid\n"); Modified: head/sbin/camcontrol/timestamp.c ============================================================================== --- head/sbin/camcontrol/timestamp.c Fri Jan 20 21:15:22 2017 (r312557) +++ head/sbin/camcontrol/timestamp.c Fri Jan 20 21:21:41 2017 (r312558) @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -138,6 +139,8 @@ set_restore_flags(struct cam_device *dev * Create the control page at the correct point in the mode_buf, it * starts after the header and the blk description. */ + assert(hdr_and_blk_length <= + sizeof(mode_buf) - sizeof(struct scsi_control_ext_page)); control_page = (struct scsi_control_ext_page *)&mode_buf [hdr_and_blk_length]; if (set_flag != 0) { @@ -240,6 +243,7 @@ report_timestamp(struct cam_device *devi bailout: if (ccb != NULL) cam_freeccb(ccb); + free(report_buf); return error; }