ObjFW  Check-in [7050b3a480]

Overview
Comment:OFDNSResolver: Do not allow IPs as local domain
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7050b3a4804642a08e95605b1755a977abbb3a6a2c3e0b570598882572a52298
User & Date: js on 2018-08-19 23:50:51
Other Links: manifest | tags
Context
2018-08-20
01:24
OFDNSResolver: Do not use gethostname() on Wii check-in: 40bf53792d user: js tags: trunk
2018-08-19
23:50
OFDNSResolver: Do not allow IPs as local domain check-in: 7050b3a480 user: js tags: trunk
23:32
Add OFDNSResolverTests check-in: 35347686ad user: js tags: trunk
Changes

Modified src/OFDNSResolver.m from [deccb8b1de] to [90b01a441b].

195
196
197
198
199
200
201
202
203
204
205
206


207







208



209

210
211



212
213
214
215
216
217
218
	     exception: (id)exception;
@end

static OFString *
domainFromHostname(void)
{
	char hostname[256];
	char *domain;

	if (gethostname(hostname, 256) != 0)
		return nil;



	if ((domain = strchr(hostname, '.')) == NULL)







		return nil;





	return [OFString stringWithCString: domain + 1
				  encoding: [OFLocale encoding]];



}

static bool
isFQDN(OFString *host, OFDNSResolverSettings *settings)
{
	const char *UTF8String = [host UTF8String];
	size_t length = [host UTF8StringLength];







|




>
>
|
>
>
>
>
>
>
>

>
>
>

>
|
|
>
>
>







195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
	     exception: (id)exception;
@end

static OFString *
domainFromHostname(void)
{
	char hostname[256];
	OFString *domain;

	if (gethostname(hostname, 256) != 0)
		return nil;

	domain = [OFString stringWithCString: hostname
				    encoding: [OFLocale encoding]];

	@try {
		of_socket_address_parse_ip(domain, 0);

		/*
		 * If we are still here, the host name is a valid IP address.
		 * We can't use that as local domain.
		 */
		return nil;
	} @catch (OFInvalidFormatException *e) {
		/* Not an IP address -> we can use it if it contains a dot. */
		size_t pos = [domain rangeOfString: @"."].location;

		if (pos == OF_NOT_FOUND)
			return nil;

		return [domain substringWithRange:
		    of_range(pos + 1, [domain length] - pos - 1)];
	}
}

static bool
isFQDN(OFString *host, OFDNSResolverSettings *settings)
{
	const char *UTF8String = [host UTF8String];
	size_t length = [host UTF8StringLength];