From 1f8a5f9d54954daa4fa35db19b5fb27fc71cfec3 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 9 Jan 2008 04:26:23 +0000 Subject: [PATCH] cd-info.c iso-info.c More error-tolerant patch from Stanislav Brabec at SuSE. iso9660.hpp: patch to compile libcdio with gcc 4.3 from Cristian Rodriguez via Stanislav Brabec. Add return statement in function returning non-void. mmc-tool.c: remove out-of-bound array access. --- include/cdio++/iso9660.hpp | 6 ++++-- src/cd-info.c | 15 +++++++++++++-- src/iso-info.c | 18 ++++++++++++++---- src/mmc-tool.c | 6 +++--- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/include/cdio++/iso9660.hpp b/include/cdio++/iso9660.hpp index 72881be4..d2f18209 100644 --- a/include/cdio++/iso9660.hpp +++ b/include/cdio++/iso9660.hpp @@ -1,7 +1,7 @@ /* -*- C++ -*- - $Id: iso9660.hpp,v 1.10 2007/11/19 19:32:11 flameeyes Exp $ + $Id: iso9660.hpp,v 1.11 2008/01/09 04:26:23 rocky Exp $ - Copyright (C) 2006 Rocky Bernstein + Copyright (C) 2006, 2008 Rocky Bernstein 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 @@ -32,6 +32,7 @@ #include #include #include // vector class library +#include using namespace std; /** ISO 9660 class. @@ -138,6 +139,7 @@ public: { free(p_stat); this->p_stat = right.p_stat; + return right; } ~Stat() diff --git a/src/cd-info.c b/src/cd-info.c index 8d2fd97e..d1ab9146 100644 --- a/src/cd-info.c +++ b/src/cd-info.c @@ -1,5 +1,5 @@ /* - $Id: cd-info.c,v 1.151 2008/01/03 14:39:29 rocky Exp $ + $Id: cd-info.c,v 1.152 2008/01/09 04:26:24 rocky Exp $ Copyright (C) 2003, 2004, 2005, 2007, 2008 Rocky Bernstein Copyright (C) 1996, 1997, 1998 Gerd Knorr @@ -518,6 +518,8 @@ print_iso9660_recurse (CdIo_t *p_cdio, const char pathname[], CdioList_t *p_dirlist = _cdio_list_new (); CdioListNode_t *entnode; uint8_t i_joliet_level; + char *translated_name = (char *) malloc(4096); + size_t translated_name_size = 4096; i_joliet_level = (opts.no_joliet) ? 0 @@ -539,7 +541,15 @@ print_iso9660_recurse (CdIo_t *p_cdio, const char pathname[], iso9660_stat_t *p_statbuf = _cdio_list_node_data (entnode); char *psz_iso_name = p_statbuf->filename; char _fullname[4096] = { 0, }; - char *translated_name = (char *) alloca(strlen(psz_iso_name)+1); + if (strlen(psz_iso_name) >= translated_name_size) { + translated_name_size = strlen(psz_iso_name)+1; + free(translated_name); + translated_name = (char *) malloc(translated_name_size); + if (!translated_name) { + report( stderr, "Error allocating memory\n" ); + return; + } + } if (yep != p_statbuf->rr.b3_rock || 1 == opts.no_rock_ridge) { iso9660_name_translate_ext(psz_iso_name, translated_name, @@ -564,6 +574,7 @@ print_iso9660_recurse (CdIo_t *p_cdio, const char pathname[], p_statbuf->rr.i_symlink = 0; } } + free (translated_name); _cdio_list_free (p_entlist, true); diff --git a/src/iso-info.c b/src/iso-info.c index fe653e01..c2683940 100644 --- a/src/iso-info.c +++ b/src/iso-info.c @@ -1,7 +1,7 @@ /* - $Id: iso-info.c,v 1.37 2008/01/03 14:39:29 rocky Exp $ + $Id: iso-info.c,v 1.38 2008/01/09 04:26:24 rocky Exp $ - Copyright (C) 2004, 2005, 2006 Rocky Bernstein + Copyright (C) 2004, 2005, 2006, 2008 Rocky Bernstein 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 @@ -205,7 +205,8 @@ print_iso9660_recurse (iso9660_t *p_iso, const char psz_path[]) CdioList_t *dirlist = _cdio_list_new (); CdioListNode_t *entnode; uint8_t i_joliet_level = iso9660_ifs_get_joliet_level(p_iso); - + char *translated_name = (char *) malloc(4096); + size_t translated_name_size = 4096; entlist = iso9660_ifs_readdir (p_iso, psz_path); if (opts.print_iso9660) { @@ -224,7 +225,15 @@ print_iso9660_recurse (iso9660_t *p_iso, const char psz_path[]) iso9660_stat_t *p_statbuf = _cdio_list_node_data (entnode); char *psz_iso_name = p_statbuf->filename; char _fullname[4096] = { 0, }; - char *translated_name = (char *) alloca(strlen(psz_iso_name)+1); + if (strlen(psz_iso_name) >= translated_name_size) { + translated_name_size = strlen(psz_iso_name)+1; + free(translated_name); + translated_name = (char *) malloc(translated_name_size); + if (!translated_name) { + report( stderr, "Error allocating memory\n" ); + return; + } + } if (yep != p_statbuf->rr.b3_rock || 1 == opts.no_rock_ridge) { iso9660_name_translate_ext(psz_iso_name, translated_name, @@ -258,6 +267,7 @@ print_iso9660_recurse (iso9660_t *p_iso, const char psz_path[]) p_statbuf->rr.i_symlink = 0; } } + free (translated_name); _cdio_list_free (entlist, true); diff --git a/src/mmc-tool.c b/src/mmc-tool.c index 972e1b3e..f81c1f16 100644 --- a/src/mmc-tool.c +++ b/src/mmc-tool.c @@ -1,5 +1,5 @@ /* - $Id: mmc-tool.c,v 1.9 2006/04/14 22:17:08 rocky Exp $ + $Id: mmc-tool.c,v 1.10 2008/01/09 04:26:24 rocky Exp $ Copyright (C) 2006 Rocky Bernstein @@ -261,7 +261,7 @@ parse_options (int argc, char *argv[]) } static void -print_mode_sense (unsigned int i_mmc_size, const uint8_t buf[22]) +print_mode_sense (unsigned int i_mmc_size, const uint8_t buf[30]) { printf("Mode sense %d information\n", i_mmc_size); if (buf[2] & 0x01) { @@ -461,7 +461,7 @@ main(int argc, char *argv[]) break; case OP_MODE_SENSE_2A: { - uint8_t buf[22] = { 0, }; /* Place to hold returned data */ + uint8_t buf[30] = { 0, }; /* Place to hold returned data */ if (p_op->arg.i_num == 10) { rc = mmc_mode_sense_10(p_cdio, buf, sizeof(buf), CDIO_MMC_CAPABILITIES_PAGE);