From owner-svn-src-stable-10@freebsd.org Sun Mar 12 04:53:28 2017 Return-Path: Delivered-To: svn-src-stable-10@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 EAC46D09EF5; Sun, 12 Mar 2017 04:53:28 +0000 (UTC) (envelope-from ngie@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 AA56C1E5A; Sun, 12 Mar 2017 04:53:28 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2C4rRgD054223; Sun, 12 Mar 2017 04:53:27 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2C4rR9Z054222; Sun, 12 Mar 2017 04:53:27 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201703120453.v2C4rR9Z054222@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Sun, 12 Mar 2017 04:53:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r315122 - stable/10/lib/libcam X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Mar 2017 04:53:29 -0000 Author: ngie Date: Sun Mar 12 04:53:27 2017 New Revision: 315122 URL: https://svnweb.freebsd.org/changeset/base/315122 Log: MFC r314189,r314190,r314191: r314189: Fix up NULL/'\0' uses and fix 2 derefs after NULL CID: 1018898, 1018899 r314190: Fix some minor style nits: put parentheses around return values r314191: Fix up r314189 The conditional in do_buff_decode(..) after the while loop was accidentally inverted. Only increment the pointer for fmt if it's not NUL. Modified: stable/10/lib/libcam/scsi_cmdparse.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libcam/scsi_cmdparse.c ============================================================================== --- stable/10/lib/libcam/scsi_cmdparse.c Sun Mar 12 04:52:09 2017 (r315121) +++ stable/10/lib/libcam/scsi_cmdparse.c Sun Mar 12 04:53:27 2017 (r315122) @@ -128,14 +128,14 @@ do_buff_decode(u_int8_t *buff, size_t le *(va_arg(*ap, int *)) = (ARG); \ assigned++; \ } \ - field_name[0] = 0; \ + field_name[0] = '\0'; \ suppress = 0; \ } while (0) u_char bits = 0; /* For bit fields */ int shift = 0; /* Bits already shifted out */ suppress = 0; - field_name[0] = 0; + field_name[0] = '\0'; while (!done) { switch(letter = *fmt) { @@ -169,9 +169,9 @@ do_buff_decode(u_int8_t *buff, size_t le fmt++; } - if (fmt) + if (*fmt != '\0') fmt++; /* Skip '}' */ - field_name[i] = 0; + field_name[i] = '\0'; break; } @@ -255,7 +255,7 @@ do_buff_decode(u_int8_t *buff, size_t le break; } if (!suppress) { - if (arg_put) + if (arg_put != NULL) (*arg_put)(puthook, (letter == 't' ? 'b' : letter), &buff[ind], width, field_name); @@ -268,7 +268,7 @@ do_buff_decode(u_int8_t *buff, size_t le for (p = dest + width - 1; p >= dest && *p == ' '; p--) - *p = 0; + *p = '\0'; } } assigned++; @@ -379,22 +379,22 @@ next_field(const char **pp, char *fmt, i field_size = 8; /* Default to byte field type... */ *fmt = 'i'; field_width = 1; /* 1 byte wide */ - if (name) - *name = 0; + if (name != NULL) + *name = '\0'; state = BETWEEN_FIELDS; while (state != DONE) { switch(state) { case BETWEEN_FIELDS: - if (*p == 0) + if (*p == '\0') state = DONE; else if (isspace(*p)) p++; else if (*p == '#') { while (*p && *p != '\n') p++; - if (p) + if (*p != '\0') p++; } else if (*p == '{') { int i = 0; @@ -410,7 +410,7 @@ next_field(const char **pp, char *fmt, i } if(name && i < n_name) - name[i] = 0; + name[i] = '\0'; if (*p == '}') p++; @@ -530,7 +530,7 @@ next_field(const char **pp, char *fmt, i if (is_error) { *error_p = 1; - return 0; + return (0); } *error_p = 0; @@ -568,7 +568,7 @@ do_encode(u_char *buff, size_t vec_max, if (suppress) value = 0; else - value = arg_get ? + value = arg_get != NULL ? (*arg_get)(gethook, field_name) : va_arg(*ap, int); } @@ -659,9 +659,9 @@ do_encode(u_char *buff, size_t vec_max, *used = ind; if (error) - return -1; + return (-1); - return encoded; + return (encoded); } int @@ -672,8 +672,8 @@ csio_decode(struct ccb_scsiio *csio, con va_start(ap, fmt); - retval = do_buff_decode(csio->data_ptr, (size_t)csio->dxfer_len, 0, 0, - fmt, &ap); + retval = do_buff_decode(csio->data_ptr, (size_t)csio->dxfer_len, + NULL, NULL, fmt, &ap); va_end(ap); @@ -705,7 +705,7 @@ buff_decode(u_int8_t *buff, size_t len, va_start(ap, fmt); - retval = do_buff_decode(buff, len, 0, 0, fmt, &ap); + retval = do_buff_decode(buff, len, NULL, NULL, fmt, &ap); va_end(ap); @@ -723,7 +723,7 @@ buff_decode_visit(u_int8_t *buff, size_t * the arg_put function. */ if (arg_put == NULL) - return(-1); + return (-1); return (do_buff_decode(buff, len, arg_put, puthook, fmt, NULL)); } @@ -779,20 +779,20 @@ csio_build_visit(struct ccb_scsiio *csio int retval; if (csio == NULL) - return(0); + return (0); /* * We need something to encode, but we can't get it without the * arg_get function. */ if (arg_get == NULL) - return(-1); + return (-1); bzero(csio, sizeof(struct ccb_scsiio)); if ((retval = do_encode(csio->cdb_io.cdb_bytes, SCSI_MAX_CDBLEN, &cmdlen, arg_get, gethook, cmd_spec, NULL)) == -1) - return(retval); + return (retval); cam_fill_csio(csio, /* retries */ retry_count, @@ -805,7 +805,7 @@ csio_build_visit(struct ccb_scsiio *csio /* cdb_len */ cmdlen, /* timeout */ timeout ? timeout : 5000); - return(retval); + return (retval); } int @@ -819,7 +819,8 @@ csio_encode(struct ccb_scsiio *csio, con va_start(ap, fmt); - retval = do_encode(csio->data_ptr, csio->dxfer_len, 0, 0, 0, fmt, &ap); + retval = do_encode(csio->data_ptr, csio->dxfer_len, NULL, NULL, NULL, + fmt, &ap); va_end(ap); @@ -836,9 +837,9 @@ buff_encode_visit(u_int8_t *buff, size_t * arg_get function. */ if (arg_get == NULL) - return(-1); + return (-1); - return (do_encode(buff, len, 0, arg_get, gethook, fmt, NULL)); + return (do_encode(buff, len, NULL, arg_get, gethook, fmt, NULL)); } int @@ -851,8 +852,8 @@ csio_encode_visit(struct ccb_scsiio *csi * arg_get function. */ if (arg_get == NULL) - return(-1); + return (-1); - return (do_encode(csio->data_ptr, csio->dxfer_len, 0, arg_get, + return (do_encode(csio->data_ptr, csio->dxfer_len, NULL, arg_get, gethook, fmt, NULL)); }