Look for a NULL destination buffer in mmc_read_cd and return

DRIVER_OP_BAD_POINTER in this particular situation.
This commit is contained in:
R. Bernstein
2011-11-27 17:47:50 -05:00
parent 0c5e4efbe1
commit c242ca3997
2 changed files with 22 additions and 4 deletions

View File

@@ -296,7 +296,10 @@ mmc_read_cd(const CdIo_t *p_cdio, void *p_buf1, lsn_t i_lsn,
void *p_buf = p_buf1;
uint8_t cdb9 = 0;
const unsigned int i_timeout = mmc_timeout_ms * (MAX_CD_READ_BLOCKS/2);
/* Catch what may be a common bug. */
if (NULL == p_buf) return DRIVER_OP_BAD_POINTER;
MMC_CMD_SETUP(CDIO_MMC_GPCMD_READ_CD);
CDIO_MMC_SET_READ_TYPE(cdb.field, read_sector_type);

View File

@@ -1,6 +1,6 @@
/* -*- C -*-
Copyright (C) 2009 Thomas Schmitt <scdbackup@gmx.net>
Copyright (C) 2010 Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2010, 2011 Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
*/
/**
Regression test for MMC commands which don't involve read/write access.
Regression test for MMC commands which don't involve write access.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -357,7 +357,22 @@ test_read(char *psz_drive_path, unsigned int i_flag)
if ((i_flag & 1) && 0 != i_ret && 2 == sense_reply.sense_key &&
0x3a == sense_reply.asc)
fprintf(stderr, "test_unit_ready: Note: No loaded media detected.\n");
i_ret = 0;
/* Call mmc_read with a null pointer and check that we get
the right return code. */
if (DRIVER_OP_BAD_POINTER !=
(i_ret = mmc_read_cd(p_cdio,
NULL, /* wrong! should be a buffer. */
200, CDIO_MMC_READ_TYPE_ANY,
false, false, 0, true, false, false,
1, 2448, 1))) {
fprintf(stderr,
"mmc_read_cd: expecting bad pointer return, got %d\n",
i_ret);
} else {
i_ret = 0;
}
ex:;
cdio_loglevel_default = old_log_level;