Language: C
Label: safe
CWE: NVD-CWE-noinfo \u2014 

Code:
ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf)
{
	if (!strcmp("local", buf)) {
		ss->ss_family = AF_LOCAL;
	}
	else if (buf[0] == '[' && buf[strlen(buf)-1] == ']') {
		struct addrinfo hints, *res0;
		
		buf[strlen(buf)-1] = '\0';

		/* getaddrinfo() is used to support scoped addresses. */
		memset(&hints, 0, sizeof(hints));
		hints.ai_family = AF_INET6;
		hints.ai_flags = AI_NUMERICHOST;
		if (getaddrinfo(buf+1, NULL, &hints, &res0) != 0)
			return 0;
		memcpy(ss, res0->ai_addr, res0->ai_addrlen);
		ss->ss_len = res0->ai_addrlen;
		freeaddrinfo(res0);
	}
	else {
		struct sockaddr_in ssin;

		memset(&ssin, 0, sizeof ssin);
		if (inet_pton(AF_INET, buf, &ssin.sin_addr) != 1)
			return 0;
		ssin.sin_family = AF_INET;
		memcpy(ss, &ssin, sizeof(ssin));
		ss->ss_len = sizeof(struct sockaddr_in);
	}
	return 1;
}