ObjFW  Check-in [725eec4cfc]

Overview
Comment:OFWindowsRegistryKey: Verify string types
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 725eec4cfc2adb2114478bba3f4fff17430b0e815728f0cdffa42e746bc5088f
User & Date: js on 2020-04-22 22:19:48
Other Links: manifest | tags
Context
2020-04-24
00:21
Add OFIPStreamSocket check-in: 3dfe642dd3 user: js tags: trunk
2020-04-22
22:19
OFWindowsRegistryKey: Verify string types check-in: 725eec4cfc user: js tags: trunk
22:04
Fix missing cast for AmigaOS check-in: 4edc83ee08 user: js tags: trunk
Changes

Modified src/OFWindowsRegistryKey.m from [752886f486] to [bed1fd3ca5].

22
23
24
25
26
27
28

29
30
31
32
33
34
35

#include <windows.h>

#import "OFCreateWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryValueFailedException.h"
#import "OFGetWindowsRegistryValueFailedException.h"

#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"

@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey







>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <windows.h>

#import "OFCreateWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryKeyFailedException.h"
#import "OFDeleteWindowsRegistryValueFailedException.h"
#import "OFGetWindowsRegistryValueFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"

@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
}

- (OFWindowsRegistryKey *)
	 createSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		disposition: (LPDWORD)disposition
{
	void *pool = objc_autoreleasePoolPush();
	LSTATUS status;
	HKEY subKey;

	if ((status = RegCreateKeyExW(_hKey, path.UTF16String, 0,
	    NULL, options, securityAndAccessRights, securityAttributes,







|







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
}

- (OFWindowsRegistryKey *)
	 createSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		disposition: (DWORD *)disposition
{
	void *pool = objc_autoreleasePoolPush();
	LSTATUS status;
	HKEY subKey;

	if ((status = RegCreateKeyExW(_hKey, path.UTF16String, 0,
	    NULL, options, securityAndAccessRights, securityAttributes,
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

	return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
							close: true]
	    autorelease];
}

- (OFData *)dataForValue: (OFString *)value
		    type: (LPDWORD)type
{
	void *pool = objc_autoreleasePoolPush();
	BYTE stackBuffer[256], *buffer = stackBuffer;
	DWORD length = sizeof(stackBuffer);
	OFMutableData *ret = nil;
	LSTATUS status;








|







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

	return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
							close: true]
	    autorelease];
}

- (OFData *)dataForValue: (OFString *)value
		    type: (DWORD *)type
{
	void *pool = objc_autoreleasePoolPush();
	BYTE stackBuffer[256], *buffer = stackBuffer;
	DWORD length = sizeof(stackBuffer);
	OFMutableData *ret = nil;
	LSTATUS status;

241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258



259
260
261
262
263
264
265
- (OFString *)stringForValue: (OFString *)value
{
	return [self stringForValue: value
			       type: NULL];
}

- (OFString *)stringForValue: (OFString *)value
			type: (LPDWORD)type
{
	void *pool = objc_autoreleasePoolPush();

	OFData *data = [self dataForValue: value
				     type: type];
	const of_char16_t *UTF16String;
	size_t length;
	OFString *ret;

	if (data == nil)
		return nil;




	UTF16String = data.items;
	length = data.count;

	if (data.itemSize != 1 || length % 2 == 1)
		@throw [OFInvalidFormatException exception];








|


>

|






>
>
>







242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
- (OFString *)stringForValue: (OFString *)value
{
	return [self stringForValue: value
			       type: NULL];
}

- (OFString *)stringForValue: (OFString *)value
			type: (DWORD *)typeOut
{
	void *pool = objc_autoreleasePoolPush();
	DWORD type;
	OFData *data = [self dataForValue: value
				     type: &type];
	const of_char16_t *UTF16String;
	size_t length;
	OFString *ret;

	if (data == nil)
		return nil;

	if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK)
		@throw [OFInvalidEncodingException exception];

	UTF16String = data.items;
	length = data.count;

	if (data.itemSize != 1 || length % 2 == 1)
		@throw [OFInvalidFormatException exception];

274
275
276
277
278
279
280



281
282
283
284
285
286
287
			length = i;
			break;
		}
	}

	ret = [[OFString alloc] initWithUTF16String: UTF16String
					     length: length];




	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (void)setString: (OFString *)string







>
>
>







279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
			length = i;
			break;
		}
	}

	ret = [[OFString alloc] initWithUTF16String: UTF16String
					     length: length];

	if (typeOut != NULL)
		*typeOut = type;

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (void)setString: (OFString *)string