ObjFW  Check-in [2e176bc500]

Overview
Comment:of_resolve_host(): Place inet_addr() inside mutex
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2e176bc500e608d3081c35b5ea4e832ccd819ea8056ae8fa5d7ec42989a8dca4
User & Date: js on 2015-02-01 14:42:44
Other Links: manifest | tags
Context
2015-02-16
08:39
Explicitly pass errno to exceptions check-in: 62e2de30b9 user: js tags: trunk
2015-02-01
14:42
of_resolve_host(): Place inet_addr() inside mutex check-in: 2e176bc500 user: js tags: trunk
11:48
ObjFW.xcodeproj: Increase LastUpgradeCheck check-in: 5318593192 user: js tags: trunk
Changes

Modified src/resolver.m from [5a537c9df8] to [65cb318889].

119
120
121
122
123
124
125



126


127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException exception];
	}
# endif
#else



	struct hostent *he;


	in_addr_t s_addr;

	char **ip;
	struct sockaddr_in *addrs, *addrsIter;

	/*
	 * If the host is an IP address, don't try resolving it.
	 * On the Wii for example, the resolver will return an error if you
	 * specify an IP address.
	 */
	if ((s_addr = inet_addr([host UTF8String])) != INADDR_NONE) {
		of_resolver_result_t *tmp;
		struct sockaddr_in *addr;

		if ((ret = calloc(2, sizeof(*ret))) == NULL)
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: 2 * sizeof(*ret)];


		if ((tmp = malloc(sizeof(*tmp))) == NULL) {
			free(ret);
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: sizeof(*tmp)];
		}








>
>
>
|
>
>

>




|
|
|







|
>







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException exception];
	}
# endif
#else
# ifdef OF_HAVE_THREADS
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
	in_addr_t s_addr;
		struct hostent *he;
	char **ip;
	struct sockaddr_in *addrs, *addrsIter;

	/*
		 * If the host is an IP address, don't try resolving it.  On
		 * the Wii for example, the resolver will return an error if
		 * you specify an IP address.
	 */
	if ((s_addr = inet_addr([host UTF8String])) != INADDR_NONE) {
		of_resolver_result_t *tmp;
		struct sockaddr_in *addr;

		if ((ret = calloc(2, sizeof(*ret))) == NULL)
			@throw [OFOutOfMemoryException
				    exceptionWithRequestedSize: 2 *
								sizeof(*ret)];

		if ((tmp = malloc(sizeof(*tmp))) == NULL) {
			free(ret);
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: sizeof(*tmp)];
		}

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

		ret[0] = tmp;
		ret[1] = NULL;

		return ret;
	}

# ifdef OF_HAVE_THREADS
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
		if ((he = gethostbyname([host UTF8String])) == NULL ||
		    he->h_addrtype != AF_INET)
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: host];

		count = 0;
		for (ip = he->h_addr_list; *ip != NULL; ip++)







<
<
<
<
<
<







173
174
175
176
177
178
179






180
181
182
183
184
185
186

		ret[0] = tmp;
		ret[1] = NULL;

		return ret;
	}







		if ((he = gethostbyname([host UTF8String])) == NULL ||
		    he->h_addrtype != AF_INET)
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: host];

		count = 0;
		for (ip = he->h_addr_list; *ip != NULL; ip++)