From 9ac1075533a1fd86dc02672e2eb1cf39b9cac155 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Wed, 28 Nov 2007 21:12:11 +0000 Subject: [PATCH] bzero the CCB header in getdevtree() and set the path properly, to avoid having random garbage in the CCB header. if the lun isn't specified in a device specifier, it should default to 0, not whatever random data happens to be in the lun variable. Obtained-from: FreeBSD --- sbin/camcontrol/camcontrol.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index 10b3d3fb03..f63776ac28 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sbin/camcontrol/camcontrol.c,v 1.21.2.13 2003/01/08 17:55:02 njl Exp $ - * $DragonFly: src/sbin/camcontrol/camcontrol.c,v 1.6 2007/11/24 01:38:46 pavalos Exp $ + * $DragonFly: src/sbin/camcontrol/camcontrol.c,v 1.7 2007/11/28 21:12:11 pavalos Exp $ */ #include @@ -296,8 +296,11 @@ getdevtree(void) return(1); } - bzero(&(&ccb.ccb_h)[1], - sizeof(struct ccb_dev_match) - sizeof(struct ccb_hdr)); + bzero(&ccb, sizeof(union ccb)); + + ccb.ccb_h.path_id = CAM_XPT_PATH_ID; + ccb.ccb_h.target_id = CAM_TARGET_WILDCARD; + ccb.ccb_h.target_lun = CAM_LUN_WILDCARD; ccb.ccb_h.func_code = XPT_DEV_MATCH; bufsize = sizeof(struct dev_match_result) * 100; @@ -3370,6 +3373,11 @@ main(int argc, char **argv) errx(1, "numeric device specification must " "be either bus:target, or " "bus:target:lun"); + /* default to 0 if lun was not specified */ + if ((arglist & CAM_ARG_LUN) == 0) { + lun = 0; + arglist |= CAM_ARG_LUN; + } optstart++; } else { if (cam_get_device(argv[2], name, sizeof name, &unit) -- 2.41.0