Commit 3afaa57
daemon: fix network address handling bugs
Fix three related issues in daemon.c's network address handling:
lookup_hostname() calls getaddrinfo() with AF_UNSPEC hints, so it may
return IPv6 results. However, the code unconditionally casts ai_addr to
sockaddr_in and passes AF_INET to inet_ntop(). On IPv6-only hosts, this
reads from the wrong struct offset, producing garbage IP addresses. Fix
by checking ai_family and handling both AF_INET and AF_INET6.
ip2str() passes the sockaddr struct size (ai_addrlen) as the output
buffer size argument to inet_ntop(). For IPv6, sizeof(sockaddr_in6) is
28 bytes but INET6_ADDRSTRLEN is 46, so long IPv6 addresses are silently
truncated. Fix by passing sizeof(ip) instead, and drop the now-unused
len parameter.
execute() logs "Connection from %s:%s" using REMOTE_ADDR and
REMOTE_PORT environment variables, but only checks REMOTE_ADDR for NULL.
If REMOTE_PORT is unset, NULL is passed to printf's %s, which is
undefined behavior. Fix by using a fallback string.
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent 67ad421 commit 3afaa57
1 file changed
Lines changed: 19 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
681 | 688 | | |
682 | 689 | | |
683 | 690 | | |
| |||
742 | 749 | | |
743 | 750 | | |
744 | 751 | | |
745 | | - | |
| 752 | + | |
746 | 753 | | |
747 | 754 | | |
748 | 755 | | |
| |||
936 | 943 | | |
937 | 944 | | |
938 | 945 | | |
939 | | - | |
| 946 | + | |
940 | 947 | | |
941 | 948 | | |
942 | 949 | | |
| |||
947 | 954 | | |
948 | 955 | | |
949 | 956 | | |
950 | | - | |
| 957 | + | |
951 | 958 | | |
952 | 959 | | |
953 | 960 | | |
954 | | - | |
| 961 | + | |
955 | 962 | | |
956 | 963 | | |
957 | 964 | | |
| |||
1008 | 1015 | | |
1009 | 1016 | | |
1010 | 1017 | | |
1011 | | - | |
| 1018 | + | |
1012 | 1019 | | |
1013 | 1020 | | |
1014 | 1021 | | |
1015 | 1022 | | |
1016 | 1023 | | |
1017 | 1024 | | |
1018 | | - | |
| 1025 | + | |
1019 | 1026 | | |
1020 | 1027 | | |
1021 | 1028 | | |
| |||
1069 | 1076 | | |
1070 | 1077 | | |
1071 | 1078 | | |
1072 | | - | |
| 1079 | + | |
1073 | 1080 | | |
1074 | 1081 | | |
1075 | 1082 | | |
1076 | 1083 | | |
1077 | 1084 | | |
1078 | 1085 | | |
1079 | 1086 | | |
1080 | | - | |
| 1087 | + | |
1081 | 1088 | | |
1082 | 1089 | | |
1083 | 1090 | | |
| |||
0 commit comments