diff --git a/src/iso.c b/src/iso.c index e69ac99049a..3f804189126 100644 --- a/src/iso.c +++ b/src/iso.c @@ -199,6 +199,37 @@ static BOOL check_iso_props(const char* psz_dirname, BOOL* is_syslinux_cfg, BOOL return FALSE; } +static void fix_syslinux(const char* psz_fullpath, const char* psz_path, const char* psz_basename) +{ + size_t i, nul_pos; + char *iso_label, *usb_label, *src, *dst; + + nul_pos = safe_strlen(psz_fullpath); + src = safe_strdup(psz_fullpath); + if (src == NULL) + return; + for (i=0; i '%s'\n", src, iso_label, usb_label); + free(iso_label); + free(usb_label); + // Fix dual BIOS + EFI support for tails and other ISOs + if ( (safe_stricmp(psz_path, efi_dirname) == 0) && (safe_stricmp(psz_basename, syslinux_cfg[0]) == 0) && + (!iso_report.has_efi_syslinux) && (dst = safe_strdup(src)) ) { + dst[nul_pos-12] = 's'; dst[nul_pos-11] = 'y'; dst[nul_pos-10] = 's'; + CopyFileA(src, dst, TRUE); + uprintf("Duplicated %s to %s\n", src, dst); + free(dst); + } +} + // Returns 0 on success, nonzero on error static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path) { @@ -207,7 +238,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha BOOL r, is_syslinux_cfg, is_old_c32[NB_OLD_C32]; int i_length; size_t i, nul_pos; - char tmp[128], *psz_fullpath = NULL, *dst; + char tmp[128], *psz_fullpath = NULL; const char* psz_basename; udf_dirent_t *p_udf_dirent2; uint8_t buf[UDF_BLOCKSIZE]; @@ -309,20 +340,8 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha // The drawback however is with cancellation. With a large file, CloseHandle() // may take forever to complete and is not interruptible. We try to detect this. ISO_BLOCKING(safe_closehandle(file_handle)); - if (is_syslinux_cfg) { - // Workaround for isolinux config files requiring an ISO label for kernel - // append that may be different from our USB label. - if (replace_in_token_data(psz_fullpath, "append", iso_report.label, iso_report.usb_label, TRUE) != NULL) - uprintf("Patched %s: '%s' -> '%s'\n", psz_fullpath, iso_report.label, iso_report.usb_label); - // Fix dual BIOS + EFI support for tails and other ISOs - if ( (safe_stricmp(psz_path, efi_dirname) == 0) && (safe_stricmp(psz_basename, syslinux_cfg[0]) == 0) && - (!iso_report.has_efi_syslinux) && (dst = safe_strdup(psz_fullpath)) ) { - dst[nul_pos-12] = 's'; dst[nul_pos-11] = 'y'; dst[nul_pos-10] = 's'; - CopyFileA(psz_fullpath, dst, TRUE); - uprintf("Duplicated %s to %s\n", psz_fullpath, dst); - free(dst); - } - } + if (is_syslinux_cfg) + fix_syslinux(psz_fullpath, psz_path, psz_basename); } safe_free(psz_fullpath); } @@ -343,7 +362,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) DWORD buf_size, wr_size, err; BOOL s, is_syslinux_cfg, is_old_c32[NB_OLD_C32], is_symlink; int i_length, r = 1; - char tmp[128], psz_fullpath[MAX_PATH], *psz_basename, *dst; + char tmp[128], psz_fullpath[MAX_PATH], *psz_basename; const char *psz_iso_name = &psz_fullpath[strlen(psz_extract_dir)]; unsigned char buf[ISO_BLOCKSIZE]; CdioListNode_t* p_entnode; @@ -467,21 +486,8 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) } } ISO_BLOCKING(safe_closehandle(file_handle)); - if (is_syslinux_cfg) { - nul_pos = safe_strlen(psz_fullpath); - for (i=0; i '%s'\n", psz_fullpath, iso_report.label, iso_report.usb_label); - // Fix dual BIOS + EFI support for tails and other ISOs - if ( (safe_stricmp(psz_path, efi_dirname) == 0) && (safe_stricmp(psz_basename, syslinux_cfg[0]) == 0) && - (!iso_report.has_efi_syslinux) && (dst = safe_strdup(psz_fullpath)) ) { - dst[nul_pos-12] = 's'; dst[nul_pos-11] = 'y'; dst[nul_pos-10] = 's'; - CopyFileA(psz_fullpath, dst, TRUE); - uprintf("Duplicated %s to %s\n", psz_fullpath, dst); - free(dst); - } - } + if (is_syslinux_cfg) + fix_syslinux(psz_fullpath, psz_path, psz_basename); } } r = 0; diff --git a/src/parser.c b/src/parser.c index 0345e2eafaa..570e7eb10de 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1067,3 +1067,32 @@ char* replace_in_token_data(const char* filename, const char* token, const char* return ret; } + + +/* + * Replace all 'c' characters in string 'src' with the subtsring 'rep' + * The returned string is allocated and must be freed by the caller. + */ +char* replace_char(const char* src, const char c, const char* rep) +{ + size_t i, j, k, count=0, str_len = safe_strlen(src), rep_len = safe_strlen(rep); + char* res; + + if ((src == NULL) || (rep == NULL)) + return NULL; + for (i=0; i