浏览代码

reject invalid address families in getaddrinfo

subsequent code assumes the address family requested is either
unspecified or one of IPv4/IPv6, and could malfunction if this
constraint is not met, so other address families should be explicitly
rejected.
Rich Felker 11 年之前
父节点
当前提交
cabe9aa974
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      src/network/getaddrinfo.c

+ 3 - 0
src/network/getaddrinfo.c

@@ -62,6 +62,9 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
 	int result;
 	int cnt;
 
+	if (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC)
+		return EAI_FAMILY;
+
 	if (host && strlen(host)>255) return EAI_NONAME;
 	if (serv && strlen(serv)>32) return EAI_SERVICE;