aboutsummaryrefslogtreecommitdiff
path: root/lib/libcam/camlib.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix a null-pointer dereference and a tautological check in cam_get_deviceAlan Somers2017-12-061-2/+7
| | | | | | | | | | | Reported by: Coverity CID: 1017964 MFC after: 3 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D13184 Notes: svn path=/head/; revision=326646
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-261-1/+3
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326219
* Fix up r316081 by using nitems(cam_errbuf) instead of sizeof(cam_errbuf)Enji Cooper2017-03-291-27/+27
| | | | | | | | | | | | | | | | | | | | | | Part of my original reasoning as far as converting the snprintf calls was to permit switching over from char[] to wchar_t[] in the future, as well as futureproof in case cam_errbuf's size was ever changed. Unfortunately, my approach was bugged because it conflated the number of items with the size of the buffer, instead of the number of elements being a fixed size != 1 byte. Use nitems(..) instead which counts the quantity of items of a specific type, as opposed to an unqualified sizeof(..) (which assumes that the number of characters is equal to the buffer size). MFC after: 2 months Noted by: cem Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=316131
* libcam: use __func__ instead of hardcoding the function name as `func_name`Enji Cooper2017-03-281-36/+30
| | | | | | | | | MFC after: 3 days Tested with: `cam_device_copy(NULL, NULL)` // ;).. Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=316115
* Use `sizeof(cam_errbuf)` instead of `CAM_ERRBUF_SIZE` in snprintf callsEnji Cooper2017-03-281-80/+79
| | | | | | | | | | | Reindent snprintf calls' arguments to match style(9) guidelines with respect to indentation. MFC after: 3 days Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=316081
* libcam: NULL out freed `ccb.cdm.matches` and `ccb.cdm.patterns` pointersEnji Cooper2017-03-201-0/+5
| | | | | | | | | | | | This is being done to avoid potential double frees with the values. Differential Revision: D9970 MFC after: 1 week Reviewed by: imp Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315639
* Fix multiple Coverity Out-of-bounds access false postive issues in CAMDon Lewis2016-05-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The currently used idiom for clearing the part of a ccb after its header generates one or two Coverity errors for each time it is used. All instances generate an Out-of-bounds access (ARRAY_VS_SINGLETON) error because of the treatment of the header as a two element array, with a pointer to the non-existent second element being passed as the starting address to bzero(). Some instances also alsp generate Out-of-bounds access (OVERRUN) errors, probably because the space being cleared is larger than the sizeofstruct ccb_hdr). In addition, this idiom is difficult for humans to understand and it is error prone. The user has to chose the proper struct ccb_* type (which does not appear in the surrounding code) for the sizeof() in the length calculation. I found several instances where the length was incorrect, which could cause either an actual out of bounds write, or incompletely clear the ccb. A better way is to write the code to clear the ccb itself starting at sizeof(ccb_hdr) bytes from the start of the ccb, and calculate the length based on the specific type of struct ccb_* being cleared as specified by the union ccb member being used. The latter can normally be seen in the nearby code. This is friendlier for Coverity and other static analysis tools because they will see that the intent is to clear the trailing part of the ccb. Wrap all of the boilerplate code in a convenient macro that only requires a pointer to the desired union ccb member (or a pointer to the union ccb itself) as an argument. Reported by: Coverity CID: 1007578, 1008684, 1009724, 1009773, 1011304, 1011306 CID: 1011307, 1011308, 1011309, 1011310, 1011311, 1011312 CID: 1011313, 1011314, 1011315, 1011316, 1011317, 1011318 CID: 1011319, 1011320, 1011321, 1011322, 1011324, 1011325 CID: 1011326, 1011327, 1011328, 1011329, 1011330, 1011374 CID: 1011390, 1011391, 1011392, 1011393, 1011394, 1011395 CID: 1011396, 1011397, 1011398, 1011399, 1011400, 1011401 CID: 1011402, 1011403, 1011404, 1011405, 1011406, 1011408 CID: 1011409, 1011410, 1011411, 1011412, 1011413, 1011414 CID: 1017461, 1018387, 1086860, 1086874, 1194257, 1229897 CID: 1229968, 1306229, 1306234, 1331282, 1331283, 1331294 CID: 1331295, 1331535, 1331536, 1331539, 1331540, 1341623 CID: 1341624, 1341637, 1341638, 1355264, 1355324 Reviewed by: scottl, ken, delphij, imp MFH: 1 month Differential Revision: https://reviews.freebsd.org/D6496 Notes: svn path=/head/; revision=300547
* Clean up trailing whitespace in lib/libcam; no functional changeEnji Cooper2016-04-141-12/+12
| | | | | | | | MFC after: 3 weeks Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=297999
* Set dev->fd to -1 when calling cam_close_spec_device with a valid dev->fdEnji Cooper2015-10-171-1/+3
| | | | | | | | | | | | | descriptor to avoid trashing valid file descriptors that access dev->fd at a later point in time PR: 192671 Submitted by: Scott Ferris <scott.ferris@isilon.com> MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=289450
* Add missing header.Nathan Whitehorn2013-10-301-0/+1
| | | | | | | Submitted by: Sean Bruno Notes: svn path=/head/; revision=257388
* printf() specifier updates to CAM to handle either 32-bit or 64-bit lun_id_t.Nathan Whitehorn2013-10-301-6/+6
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=257382
* Fix a typo: XPORT_SPI should be tested against transport, nor protocol.Xin LI2013-06-031-1/+1
| | | | | | | | | Submitted by: Sascha Wildner <swildner dragonflybsd org> Reviewed by: mjacob MFC after: 2 weeks Notes: svn path=/head/; revision=251349
* Use snprintf(3) constantly when generating CAM error messages.Jaakko Heinonen2012-03-031-44/+58
| | | | | | | | | PR: bin/57088 Submitted by: Rui Lopes, arundel MFC after: 2 weeks Notes: svn path=/head/; revision=232450
* Replace index() and rindex() calls with strchr() and strrchr().Ed Schouten2012-01-031-1/+1
| | | | | | | | | | | | | The index() and rindex() functions were marked LEGACY in the 2001 revision of POSIX and were subsequently removed from the 2008 revision. The strchr() and strrchr() functions are part of the C standard. This makes the source code a lot more consistent, as most of these C files also call into other str*() routines. In fact, about a dozen already perform strchr() calls. Notes: svn path=/head/; revision=229403
* camlib.c: update one overlooked commentAndriy Gapon2010-10-111-3/+3
| | | | Notes: svn path=/head/; revision=213703
* cam_get_device, cam_open_device: make behavior simpler and more deterministicAndriy Gapon2010-10-111-85/+19
| | | | | | | | | | | | | | | | | | | Remove or re-work support for the several features from the past: - remove incomplete support for trimming slice/partition names - remove mapping from old device names "sd" and "st" - remove whitespace trimming - remove unconditional skipping of leading 'r' in a device name - skip leading 'n' or 'e' only if the following device name matches a list of known devices that support no-rewind and eject-on-close features; currently this is only sa(4) - reflect the above changes in comments in code and in cam(3) - remove a note cautioning against use of cam_get_device and cam_open_device in cam(3) Reviewed by: mjacob Notes: svn path=/head/; revision=213682
* Supply a valid Connect ID when issuing XPT_DEV_MATCH, whichMarius Strobl2008-10-271-0/+3
| | | | | | | | | | | | | | | | | according to my reading of the CAM draft is mandatory for all CCB function calls and enforced by xptioctl() since at least r168752. Previously we happened to use 0 as the Path ID, causing the XPT_DEV_MATCH call to fail if there's no SCSI bus 0. Basically the same bug was also fixed the same way for camcontrol(8) as part of r126514. PR: 127605 Submitted by: Eygene Ryabinkin Approved by: silence from ken and scottl MFC after: 1 week Notes: svn path=/head/; revision=184379
* 2nd and final commit that moves us to CAM_NEW_TRAN_CODEMatt Jacob2006-11-021-4/+12
| | | | | | | | | as the default. Reviewed by multitudes. Notes: svn path=/head/; revision=163896
* Go with a different version of the previous patch so to preserve errno.Joe Marcus Clarke2006-04-301-5/+5
| | | | | | | Approved by: scottl (implicit) Notes: svn path=/head/; revision=158171
* Fix a file descriptor leak in cam_lookup_pass() when the ioctl to findJoe Marcus Clarke2006-04-301-4/+5
| | | | | | | | | | the passthru device fails. Approved by: scottl MFC after: 1 day Notes: svn path=/head/; revision=158170
* Better memory handling:Xin LI2005-07-131-4/+7
| | | | | | | | | | | | | | | - It is acceptable to call free(3) when the given pointer itself is NULL, so we do not need to determine NULL before passing a pointer to free(3) - Handle failure of malloc(3) MT6/5 Candidate Submitted by: Dan Lukes <dan at obluda cz> PR: bin/83352 Notes: svn path=/head/; revision=147949
* Change a couple of comments so that GCC doesn't think that they containScott Long2004-07-291-3/+3
| | | | | | | tri-graphs. Notes: svn path=/head/; revision=132843
* string cleanup:Kenneth D. Merry2002-05-141-14/+12
| | | | | | | | | | | | | | - fix a potential overrun made worse by rev 1.5 of camlib.h - change strncpy() and strcpy() calls to strlcpy() - use sizeof(string[]) instead of STRING_LEN to avoid future problems - get rid of an unused variable Thanks to BDE for pointing out some of the problems. MFC after: 2 weeks Notes: svn path=/head/; revision=96559
* Add __FBSDID()s to libcamMatthew Dillon2001-09-301-2/+3
| | | | Notes: svn path=/head/; revision=84199
* Make sure you don't have a file descriptor leak for the 'real'Matt Jacob2001-07-041-1/+5
| | | | | | | | | | | | | underlying CAM device. This needs to be checked not only in the open routine, but the device->fd has to be initialized as well. PR: 28688 Submitted (partially) by: T. William Wells <bill@twwells.com> MFC after: 2 weeks Notes: svn path=/head/; revision=79183
* get pd_type from inquiry data itselfMatt Jacob2000-01-161-1/+1
| | | | Notes: svn path=/head/; revision=56122
* Fix a file descriptor leak in cam_open_btl(). The xpt device was opened,Kenneth D. Merry1999-09-121-1/+5
| | | | | | | | | but never closed. Submitted by: amobbs@allstor-sw.co.uk Notes: svn path=/head/; revision=51213
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50476
* cam_get_device() was returning 0 on failure, and 1 on success, whileMike Pritchard1999-06-151-10/+10
| | | | | | | | | | | camcontrol(8) and the documentation in camlib.c and cam(3) all expect -1 on failure and 0 on success. Updated camlib.c to return the values specified by the documentation. PR: 12023 Notes: svn path=/head/; revision=47933
* Use snprintf to make sure we don't overflow a buffer.Kenneth D. Merry1998-11-151-4/+5
| | | | Notes: svn path=/head/; revision=41190
* Fix an error message. (it was using an uninitialized variable)Kenneth D. Merry1998-11-151-2/+2
| | | | | | | Reported by: dan@math.berkeley.edu (Dan Strick) Notes: svn path=/head/; revision=41189
* Add a "dummy light" (actually two dummy lights) to catch people who don'tKenneth D. Merry1998-10-121-4/+27
| | | | | | | | | | | | have the passthrough device configured in their kernel. This will hopefully reduce the number of people complaining that they can't get {camcontrol, xmcd, tosha, cdrecord, etc.} to work. Reviewed by: gibbs Notes: svn path=/head/; revision=40271
* CAM userland utility library, a replacement for libscsi.Justin T. Gibbs1998-09-151-0/+757
Submitted by: "Kenneth D. Merry" <ken@FreeBSD.org> Notes: svn path=/head/; revision=39209