瀏覽代碼

fix getservby*() with null pointer for protocol argument

not sure this is the best fix but it should work
Rich Felker 12 年之前
父節點
當前提交
06650b9684
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 4 0
      src/network/getservbyname_r.c
  2. 4 0
      src/network/getservbyport_r.c

+ 4 - 0
src/network/getservbyname_r.c

@@ -12,6 +12,10 @@ int getservbyname_r(const char *name, const char *prots,
 	struct addrinfo *ai, hint = { .ai_family = AF_INET };
 	int i;
 
+	if (!prots) return -(
+		getservbyname_r(name, "tcp", se, buf, buflen, res)
+		&& getservbyname_r(name, "udp", se, buf, buflen, res) );
+
 	/* Align buffer */
 	i = (uintptr_t)buf & sizeof(char *)-1;
 	if (!i) i = sizeof(char *);

+ 4 - 0
src/network/getservbyport_r.c

@@ -15,6 +15,10 @@ int getservbyport_r(int port, const char *prots,
 		.sin_port = port,
 	};
 
+	if (!prots) return -(
+		getservbyport_r(port, "tcp", se, buf, buflen, res)
+		&& getservbyport_r(port, "udp", se, buf, buflen, res) );
+
 	/* Align buffer */
 	i = (uintptr_t)buf & sizeof(char *)-1;
 	if (!i) i = sizeof(char *);