diff options
author | jedgar <jedgar@FreeBSD.org> | 2000-12-01 12:02:16 +0000 |
---|---|---|
committer | jedgar <jedgar@FreeBSD.org> | 2000-12-01 12:02:16 +0000 |
commit | 24771a5a3c2ba89e3afb649345fb8b30af12f94a (patch) | |
tree | a896a86f554d5778ea4ab61baae7bffc71f0ed23 /sbin/camcontrol/camcontrol.c | |
parent | e3960a89e4a021190b2db9896ea16ce361c17ff6 (diff) | |
download | FreeBSD-src-24771a5a3c2ba89e3afb649345fb8b30af12f94a.zip FreeBSD-src-24771a5a3c2ba89e3afb649345fb8b30af12f94a.tar.gz |
Properly check malloc(3) return values
Approved by: ken
Diffstat (limited to 'sbin/camcontrol/camcontrol.c')
-rw-r--r-- | sbin/camcontrol/camcontrol.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index ec42053..87e6fb9 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -282,6 +282,11 @@ getdevtree(void) bufsize = sizeof(struct dev_match_result) * 100; ccb.cdm.match_buf_len = bufsize; ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize); + if (ccb.cdm.matches == NULL) { + warnx("can't malloc memory for matches"); + close(fd); + return(1); + } ccb.cdm.num_matches = 0; /* @@ -1202,6 +1207,11 @@ readdefects(struct cam_device *device, int argc, char **argv, * to hold them all. */ defect_list = malloc(dlist_length); + if (defect_list == NULL) { + warnx("can't malloc memory for defect list"); + error = 1; + goto defect_bailout; + } rdd_cdb =(struct scsi_read_defect_data_10 *)&ccb->csio.cdb_io.cdb_bytes; @@ -1678,6 +1688,11 @@ scsicmd(struct cam_device *device, int argc, char **argv, char *combinedopt, fd_data = 1; data_ptr = (u_int8_t *)malloc(data_bytes); + if (data_ptr == NULL) { + warnx("can't malloc memory for data_ptr"); + error = 1; + goto scsicmd_bailout; + } break; case 'o': if (arglist & CAM_ARG_CMD_IN) { @@ -1700,6 +1715,11 @@ scsicmd(struct cam_device *device, int argc, char **argv, char *combinedopt, hook.got = 0; datastr = cget(&hook, NULL); data_ptr = (u_int8_t *)malloc(data_bytes); + if (data_ptr == NULL) { + warnx("can't malloc memory for data_ptr"); + error = 1; + goto scsicmd_bailout; + } /* * If the user supplied "-" instead of a format, he * wants the data to be read from stdin. |