mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] add arbitrary buffer allocation to GetResource()
* If duplicate is TRUE and len is non-zero, then a buffer of len size, padded with zeroes, is allocated for the resource.
This commit is contained in:
		
							parent
							
								
									841b79f45d
								
							
						
					
					
						commit
						b8579c04da
					
				
					 6 changed files with 27 additions and 12 deletions
				
			
		|  | @ -2,7 +2,7 @@ | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll |  * DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll | ||||||
|  * (MS WinME DOS) or from the embedded FreeDOS resource files |  * (MS WinME DOS) or from the embedded FreeDOS resource files | ||||||
|  * Copyright © 2011-2017 Pete Batard <pete@akeo.ie> |  * Copyright © 2011-2020 Pete Batard <pete@akeo.ie> | ||||||
|  * |  * | ||||||
|  * This program is free software: you can redistribute it and/or modify |  * 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 |  * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -317,6 +317,7 @@ static BOOL ExtractMSDOS(const char* path) | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	DiskImageSize = 0; | ||||||
| 	DiskImage = (BYTE*)GetResource(hDLL, MAKEINTRESOURCEA(1), "BINFILE", "disk image", &DiskImageSize, TRUE); | 	DiskImage = (BYTE*)GetResource(hDLL, MAKEINTRESOURCEA(1), "BINFILE", "disk image", &DiskImageSize, TRUE); | ||||||
| 	if (DiskImage == NULL) | 	if (DiskImage == NULL) | ||||||
| 		goto out; | 		goto out; | ||||||
|  |  | ||||||
|  | @ -1633,6 +1633,7 @@ static void InitDialog(HWND hDlg) | ||||||
| 	uprintf(APPLICATION_NAME " " APPLICATION_ARCH " v%d.%d.%d%s%s", rufus_version[0], rufus_version[1], rufus_version[2], | 	uprintf(APPLICATION_NAME " " APPLICATION_ARCH " v%d.%d.%d%s%s", rufus_version[0], rufus_version[1], rufus_version[2], | ||||||
| 		IsAlphaOrBeta(), (ini_file != NULL)?"(Portable)":""); | 		IsAlphaOrBeta(), (ini_file != NULL)?"(Portable)":""); | ||||||
| 	for (i=0; i<ARRAYSIZE(resource); i++) { | 	for (i=0; i<ARRAYSIZE(resource); i++) { | ||||||
|  | 		len = 0; | ||||||
| 		buf = (char*)GetResource(hMainInstance, resource[i], _RT_RCDATA, "ldlinux_sys", &len, TRUE); | 		buf = (char*)GetResource(hMainInstance, resource[i], _RT_RCDATA, "ldlinux_sys", &len, TRUE); | ||||||
| 		if (buf == NULL) { | 		if (buf == NULL) { | ||||||
| 			uprintf("Warning: could not read embedded Syslinux v%d version", i+4); | 			uprintf("Warning: could not read embedded Syslinux v%d version", i+4); | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 232, 326 | IDD_DIALOG DIALOGEX 12, 12, 232, 326 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| EXSTYLE WS_EX_ACCEPTFILES | EXSTYLE WS_EX_ACCEPTFILES | ||||||
| CAPTION "Rufus 3.9.1616" | CAPTION "Rufus 3.9.1617" | ||||||
| FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP |     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP | ||||||
|  | @ -394,8 +394,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 3,9,1616,0 |  FILEVERSION 3,9,1617,0 | ||||||
|  PRODUCTVERSION 3,9,1616,0 |  PRODUCTVERSION 3,9,1617,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -413,13 +413,13 @@ BEGIN | ||||||
|             VALUE "Comments", "https://rufus.ie" |             VALUE "Comments", "https://rufus.ie" | ||||||
|             VALUE "CompanyName", "Akeo Consulting" |             VALUE "CompanyName", "Akeo Consulting" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "3.9.1616" |             VALUE "FileVersion", "3.9.1617" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" |             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" | ||||||
|             VALUE "OriginalFilename", "rufus-3.9.exe" |             VALUE "OriginalFilename", "rufus-3.9.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "3.9.1616" |             VALUE "ProductVersion", "3.9.1617" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
							
								
								
									
										20
									
								
								src/stdfn.c
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								src/stdfn.c
									
										
									
									
									
								
							|  | @ -549,10 +549,17 @@ out: | ||||||
| 	return ret; | 	return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  |  * Get a resource from the RC. If needed that resource can be duplicated. | ||||||
|  |  * If duplicate is true and len is non-zero, the a zeroed buffer of 'len' | ||||||
|  |  * size is allocated for the resource. Else the buffer is allocate for | ||||||
|  |  * the resource size. | ||||||
|  |  */ | ||||||
| unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate) | unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate) | ||||||
| { | { | ||||||
| 	HGLOBAL res_handle; | 	HGLOBAL res_handle; | ||||||
| 	HRSRC res; | 	HRSRC res; | ||||||
|  | 	DWORD res_len; | ||||||
| 	unsigned char* p = NULL; | 	unsigned char* p = NULL; | ||||||
| 
 | 
 | ||||||
| 	res = FindResourceA(module, name, type); | 	res = FindResourceA(module, name, type); | ||||||
|  | @ -565,18 +572,23 @@ unsigned char* GetResource(HMODULE module, char* name, char* type, const char* d | ||||||
| 		uprintf("Could not load resource '%s': %s\n", desc, WindowsErrorString()); | 		uprintf("Could not load resource '%s': %s\n", desc, WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	*len = SizeofResource(module, res); | 	res_len = SizeofResource(module, res); | ||||||
| 
 | 
 | ||||||
| 	if (duplicate) { | 	if (duplicate) { | ||||||
| 		p = (unsigned char*)malloc(*len); | 		if (*len == 0) | ||||||
|  | 			*len = res_len; | ||||||
|  | 		p = (unsigned char*)calloc(*len, 1); | ||||||
| 		if (p == NULL) { | 		if (p == NULL) { | ||||||
| 			uprintf("Coult not allocate resource '%s'\n", desc); | 			uprintf("Could not allocate resource '%s'\n", desc); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		memcpy(p, LockResource(res_handle), *len); | 		memcpy(p, LockResource(res_handle), res_len); | ||||||
|  | 		if (res_len < *len) | ||||||
|  | 			uprintf("Warning: Resource '%s' was truncated by %d bytes!\n", desc, *len - res_len); | ||||||
| 	} else { | 	} else { | ||||||
| 		p = (unsigned char*)LockResource(res_handle); | 		p = (unsigned char*)LockResource(res_handle); | ||||||
| 	} | 	} | ||||||
|  | 	*len = res_len; | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
| 	return p; | 	return p; | ||||||
|  |  | ||||||
|  | @ -1856,7 +1856,7 @@ LPCDLGTEMPLATE GetDialogTemplate(int Dialog_ID) | ||||||
| 	int i; | 	int i; | ||||||
| 	const char thai_id[] = "th-TH"; | 	const char thai_id[] = "th-TH"; | ||||||
| 	size_t len; | 	size_t len; | ||||||
| 	DWORD size; | 	DWORD size = 0; | ||||||
| 	DWORD* dwBuf; | 	DWORD* dwBuf; | ||||||
| 	WCHAR* wBuf; | 	WCHAR* wBuf; | ||||||
| 	LPCDLGTEMPLATE rcTemplate = (LPCDLGTEMPLATE) GetResource(hMainInstance, MAKEINTRESOURCEA(Dialog_ID), | 	LPCDLGTEMPLATE rcTemplate = (LPCDLGTEMPLATE) GetResource(hMainInstance, MAKEINTRESOURCEA(Dialog_ID), | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
|  * |  * | ||||||
|  *   Copyright 2003 Lars Munch Christensen - All Rights Reserved |  *   Copyright 2003 Lars Munch Christensen - All Rights Reserved | ||||||
|  *   Copyright 1998-2008 H. Peter Anvin - All Rights Reserved |  *   Copyright 1998-2008 H. Peter Anvin - All Rights Reserved | ||||||
|  *   Copyright 2012-2018 Pete Batard |  *   Copyright 2012-2020 Pete Batard | ||||||
|  * |  * | ||||||
|  *   Based on the Linux installer program for SYSLINUX by H. Peter Anvin |  *   Based on the Linux installer program for SYSLINUX by H. Peter Anvin | ||||||
|  * |  * | ||||||
|  | @ -185,6 +185,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) | ||||||
| 	} else { | 	} else { | ||||||
| 		for (i=0; i<2; i++) { | 		for (i=0; i<2; i++) { | ||||||
| 		static_sprintf(tmp, "%s.%s", ldlinux, ldlinux_ext[i]); | 		static_sprintf(tmp, "%s.%s", ldlinux, ldlinux_ext[i]); | ||||||
|  | 		syslinux_ldlinux_len[i] = 0; | ||||||
| 		syslinux_ldlinux[i] = GetResource(hMainInstance, resource[use_v5?1:0][i], | 		syslinux_ldlinux[i] = GetResource(hMainInstance, resource[use_v5?1:0][i], | ||||||
| 			_RT_RCDATA, tmp, &syslinux_ldlinux_len[i], TRUE); | 			_RT_RCDATA, tmp, &syslinux_ldlinux_len[i], TRUE); | ||||||
| 		if (syslinux_ldlinux[i] == NULL) | 		if (syslinux_ldlinux[i] == NULL) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue