Author: hbelusca Date: Fri Jan 8 20:25:30 2016 New Revision: 70553
URL: http://svn.reactos.org/svn/reactos?rev=70553&view=rev Log: [CDMAKE] - #if _WIN32 --> #ifdef _WIN32 - Define the "max" macro only if needed. - Fix a comment. - Plug a memory leak ('case_name' not freed in the "!*case_name" case of the dir_hash_create_dir function). - Return a non-zero value (the file structure pointer) from dir_hash_add_file in case we succeed in creating the file in the ISO structure, and NULL otherwise (i.e. when the filename is empty). In that latter case we fail the hard way. No-named files are completely invalid in ISO archives. Now, the following testcase (e.g. to be added into bootcd.lst): reactos/reactos.exe/=C:/test/reactos.exe fails as expected (before, we were able to create a directory named "reactos/reactos.exe", and inside, a no-named file with the contents of C:/test/reactos.exe).
Modified: trunk/reactos/tools/cdmake/cdmake.c trunk/reactos/tools/cdmake/dirhash.c trunk/reactos/tools/cdmake/dirhash.h
Modified: trunk/reactos/tools/cdmake/cdmake.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/cdmake.c?rev=7... ============================================================================== --- trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] Fri Jan 8 20:25:30 2016 @@ -619,7 +619,7 @@
#if defined(_WIN32) && !defined(strcasecmp) #define strcasecmp stricmp -#endif//_WIN32 +#endif // _WIN32
static BOOL cdname_exists(PDIR_RECORD d) { @@ -696,7 +696,7 @@ filename_counter = 1; while (cdname_exists(d)) { - // the file name must be least 8 char long + // the file name must be at least 8 chars long if (strlen(d->name_on_cd)<8) error_exit("'%s' is a duplicate file name, aborting...", filename);
@@ -704,7 +704,9 @@ error_exit("'%s' is a duplicate file name, aborting...", filename);
// max 255 times for equal short filename - if (filename_counter>255) error_exit("'%s' is a duplicate file name, aborting...", filename); + if (filename_counter>255) + error_exit("'%s' is a duplicate file name, aborting...", filename); + d->name_on_cd[8] = '~'; memset(&d->name_on_cd[9],0,5); sprintf(&d->name_on_cd[9],"%d",filename_counter); @@ -729,7 +731,7 @@ for the specified parent and returns a pointer to the new record. -----------------------------------------------------------------------------*/
-#if _WIN32 +#ifdef _WIN32
/* Win32 version */ PDIR_RECORD @@ -1167,7 +1169,7 @@ return new_d; }
-#if _WIN32 +#ifdef _WIN32 static BOOL get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info) { @@ -1195,7 +1197,7 @@ scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir) { PDIR_RECORD new_d; -#if _WIN32 +#ifdef _WIN32 HANDLE open_file; LARGE_INTEGER file_size; #else @@ -1210,7 +1212,7 @@ { if (strcmp(file->target_name, DIRECTORY_TIMESTAMP) == 0) { -#if _WIN32 +#ifdef _WIN32 if ((open_file = CreateFileA(file->source_name, GENERIC_READ, FILE_SHARE_READ, @@ -1246,7 +1248,7 @@ } new_d = new_empty_dirrecord(d, FALSE); parse_filename_into_dirrecord(file->target_name, new_d, FALSE); -#if _WIN32 +#ifdef _WIN32 if ((open_file = CreateFileA(file->source_name, GENERIC_READ, FILE_SHARE_READ, @@ -1271,7 +1273,7 @@ #else if (stat(file->source_name, &stbuf) == -1) { - error_exit("Cannot find '%s' (target %s)\n", + error_exit("Cannot find '%s' (target '%s')\n", file->source_name, file->target_name); } @@ -2241,7 +2243,7 @@ } else { - char *trimmedline, *targetname, *srcname, *eq, *normdir; + char *trimmedline, *targetname, *normdir, *srcname, *eq; char lineread[1024];
FILE *f = fopen(source+1, "r"); @@ -2268,17 +2270,17 @@ targetname = strtok(lineread, "="); srcname = strtok(NULL, "");
-#if _WIN32 +#ifdef _WIN32 if (_access(srcname, R_OK) == 0) - dir_hash_add_file(&specified_files, srcname, targetname); - else - error_exit("Cannot access file '%s' (target %s)\n", srcname, targetname); #else if (access(srcname, R_OK) == 0) - dir_hash_add_file(&specified_files, srcname, targetname); +#endif + { + if (!dir_hash_add_file(&specified_files, srcname, targetname)) + error_exit("Target '%s' (file '%s') is invalid\n", targetname, srcname); + } else - error_exit("Cannot access file '%s' (target %s)\n", srcname, targetname); -#endif + error_exit("Cannot access file '%s' (target '%s')\n", srcname, targetname); } } fclose(f);
Modified: trunk/reactos/tools/cdmake/dirhash.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/dirhash.c?rev=... ============================================================================== --- trunk/reactos/tools/cdmake/dirhash.c [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/dirhash.c [iso-8859-1] Fri Jan 8 20:25:30 2016 @@ -12,7 +12,9 @@ #include "config.h" #include "dirhash.h"
+#ifndef max #define max(a, b) ((a) > (b) ? (a) : (b)) +#endif
/* This is the famous DJB hash */ static unsigned int @@ -148,7 +150,11 @@ free(parentcase);
/* See the remark above */ - if (!*case_name) return parent_de; + if (!*case_name) + { + free(case_name); + return parent_de; + }
/* Now create the directory */ de = calloc(1, sizeof(*de)); @@ -168,7 +174,8 @@ return de; }
-void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target) +struct target_file * +dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target) { struct target_file *tf; struct target_dir_entry *de; @@ -176,8 +183,14 @@ char *targetfile = NULL; char *targetnorm;
- /* Create first the directory */ + /* First create the directory; check whether the file name is valid and bail out if not */ split_path(target, &targetdir, &targetfile); + if (!*targetfile) + { + free(targetdir); + free(targetfile); + return NULL; + } targetnorm = strdup(targetdir); normalize_dirname(targetnorm); de = dir_hash_create_dir(dh, targetdir, targetnorm); @@ -190,6 +203,8 @@ de->head = tf; tf->source_name = strdup(source); tf->target_name = targetfile; + + return tf; }
static void
Modified: trunk/reactos/tools/cdmake/dirhash.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/dirhash.h?rev=... ============================================================================== --- trunk/reactos/tools/cdmake/dirhash.h [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/dirhash.h [iso-8859-1] Fri Jan 8 20:25:30 2016 @@ -5,6 +5,7 @@ * PURPOSE: CD-ROM Premastering Utility - Directory names hashing * PROGRAMMERS: Art Yerkes */ + #ifndef _DIRHASH_H_ #define _DIRHASH_H_
@@ -37,9 +38,13 @@ };
void normalize_dirname(char *filename); -void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target); + struct target_dir_entry * dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char *targetnorm); + +struct target_file * +dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target); + void dir_hash_destroy(struct target_dir_hash *dh);
#endif // _DIRHASH_H_