mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	windows.c: Fix possible assert when passing NULL to *open()
On Win32 subsurface_fopen() can reach an assert in windows.c: utf8_to_utf16(), if NULL is passed for 'path'. Let's return NULL/-1 for some of the *open() functions in there. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									7f4d1a9f32
								
							
						
					
					
						commit
						304f5e8569
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		|  | @ -114,6 +114,8 @@ static wchar_t *utf8_to_utf16_fl(const char *utf8, char *file, int line) | ||||||
| int subsurface_open(const char *path, int oflags, mode_t mode) | int subsurface_open(const char *path, int oflags, mode_t mode) | ||||||
| { | { | ||||||
| 	int ret = -1; | 	int ret = -1; | ||||||
|  | 	if (!path) | ||||||
|  | 		return -1; | ||||||
| 	wchar_t *wpath = utf8_to_utf16(path); | 	wchar_t *wpath = utf8_to_utf16(path); | ||||||
| 	if (wpath) { | 	if (wpath) { | ||||||
| 		ret = _wopen(wpath, oflags, mode); | 		ret = _wopen(wpath, oflags, mode); | ||||||
|  | @ -126,6 +128,8 @@ int subsurface_open(const char *path, int oflags, mode_t mode) | ||||||
| FILE *subsurface_fopen(const char *path, const char *mode) | FILE *subsurface_fopen(const char *path, const char *mode) | ||||||
| { | { | ||||||
| 	FILE *ret = NULL; | 	FILE *ret = NULL; | ||||||
|  | 	if (!path) | ||||||
|  | 		return ret; | ||||||
| 	wchar_t *wpath = utf8_to_utf16(path); | 	wchar_t *wpath = utf8_to_utf16(path); | ||||||
| 	if (wpath) { | 	if (wpath) { | ||||||
| 		const int len = strlen(mode); | 		const int len = strlen(mode); | ||||||
|  | @ -144,6 +148,8 @@ FILE *subsurface_fopen(const char *path, const char *mode) | ||||||
| void *subsurface_opendir(const char *path) | void *subsurface_opendir(const char *path) | ||||||
| { | { | ||||||
| 	_WDIR *ret = NULL; | 	_WDIR *ret = NULL; | ||||||
|  | 	if (!path) | ||||||
|  | 		return ret; | ||||||
| 	wchar_t *wpath = utf8_to_utf16(path); | 	wchar_t *wpath = utf8_to_utf16(path); | ||||||
| 	if (wpath) { | 	if (wpath) { | ||||||
| 		ret = _wopendir(wpath); | 		ret = _wopendir(wpath); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue