summaryrefslogtreecommitdiff
path: root/src/network
AgeCommit message (Collapse)AuthorLines
2015-03-30fix internal buffer overrun in inet_ptonRich Felker-2/+3
one stop condition for parsing abbreviated ipv6 addressed was missed, allowing the internal ip[] buffer to overflow. this patch adds the missing stop condition and masks the array index so that, in case there are any remaining stop conditions missing, overflowing the buffer is not possible. (cherry picked from commit fc13acc3dcb5b1f215c007f583a63551f6a71363)
2015-03-30fix dn_expand empty name handling and offsets to 0Szabolcs Nagy-6/+9
Empty name was rejected in dn_expand since commit 56b57f37a46dab432247bf29d96fcb11fbd02a6d which is a regression as reported by Natanael Copa. Furthermore if an offset pointer in a compressed name pointed to a terminating 0 byte (instead of a label) the returned name was not null terminated. (cherry picked from commit 49d2c8c6bcf8c926e52c7f510033b6adc31355f5)
2014-07-28fix gethostby*_r result pointer value on errorRich Felker-0/+4
according to the documentation in the man pages, the GNU extension functions gethostbyaddr_r, gethostbyname_r and gethostbyname2_r are guaranteed to set the result pointer to NULL in case of error or no result. corresponds to commit fe82bb9b921be34370e6b71a1c6f062c20999ae0 in master branch.
2014-06-06fix multiple validation issues in dns response label parsingSzabolcs Nagy-4/+6
Due to an error introduced in commit fcc522c92335783293ac19df318415cd97fbf66b, checking of the remaining output buffer space was not performed correctly, allowing malformed input to write past the end of the buffer. In addition, the loop detection logic failed to account for the possibility of infinite loops with no output, which would hang the function. The output size is now limited more strictly so only names with valid length are accepted. (cherry picked from commit b3d9e0b94ea73c68ef4169ec82c898ce59a4e30a)
2014-06-06remove some dummy "ent" function aliases that duplicated real onesRich Felker-8/+0
the service and protocol functions are defined also in other files, and the protocol ones are actually non-nops elsewhere, so the weak definitions in ent.c could have prevented the strong definitions from getting pulled in and used in some static programs. (cherry picked from commit 934aa1350b96461f205ad69c95e8f6f035f6b62c)
2014-06-06fix if_nametoindex return value when interface does not existRich Felker-1/+1
the return value is unsigned, so negative results for "errors" do not make sense; 0 is the value reserved for when the interface name does not exist. (cherry picked from commit 8041af59881219c32267c3491bee43591d3c3fe6)
2014-02-21add fallback emulation for accept4 on old kernelsRich Felker-1/+12
the other atomic FD_CLOEXEC interfaces (dup3, pipe2, socket) already had such emulation in place. the justification for doing the emulation here is the same as for the other functions: it allows applications to simply use accept4 rather than having to have their own fallback code for ENOSYS/EINVAL (which one you get is arch-specific!) and there is no reasonable way an application could benefit from knowing the operation is emulated/non-atomic since there is no workaround at the application level for non-atomicity (that is the whole reason these interfaces were added).
2014-02-13add ipv6 and icmpv6 to getprotoent-family functionsRich Felker-1/+3
based on patch by orc.
2014-02-13fix typo in table for getprotoent that caused out-of-bound readsRich Felker-1/+1
this was unlikely to lead to any crash or dangerous behavior, but caused adjacent string constants to be treated as part of the protocols table, possibly returning nonsensical results for unknown protocol names/numbers or when getprotoent was called in a loop to enumerate all protocols.
2014-01-06fix argument types for legacy function inet_makeaddrRich Felker-2/+1
the type int was taken from seemingly erroneous man pages. glibc uses in_addr_t (uint32_t), and semantically, the arguments should be unsigned.
2013-12-20implement legacy function herrorRich Felker-0/+8
based on patch by Timo Teräs; greatly simplified to use fprintf.
2013-12-12include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy-18/+3
2013-12-12remove an unnecessary check in inet_ptonSzabolcs Nagy-2/+1
at most 4 hexadecimal digits are processed in one field so the value cannot overflow. the netdb.h header was not used.
2013-11-30support mix of IPv4 and v6 nameservers in resolv.confRich Felker-5/+31
a v6 socket will only be used if there is at least one v6 nameserver address. if the kernel lacks v6 support, the code will fall back to using a v4 socket and requests to v6 servers will silently fail. when using a v6 socket, v4 addresses are converted to v4-mapped form and setsockopt is used to ensure that the v6 socket can accept both v4 and v6 traffic (this is on-by-default on Linux but the default is configurable in /proc and so it needs to be set explicitly on the socket level). this scheme avoids increasing resource usage during lookups and allows the existing network io loop to be used without modification. previously, nameservers whose address family did not match the address family of the first-listed nameserver were simply ignored. prior to recent __ipparse fixes, they were not ignored but erroneously parsed.
2013-11-27reject invalid address families in getaddrinfoRich Felker-0/+3
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.
2013-11-25remove duplicate includes from dynlink.c, strfmon.c and getaddrinfo.cSzabolcs Nagy-3/+0
2013-11-24Fix dn_comp prototype and add stubMichael Forney-0/+9
This function is used by ping6 from iputils.
2013-11-23Fix dn_expand pointer followingMichael Forney-1/+1
2013-11-20fix fd leak (missing close-on-exec) in getifaddrsRich Felker-1/+1
2013-11-02fix regression in inet_aton due to misinterpretation of __ipparse returnRich Felker-3/+3
inet_aton returns a boolean success value, whereas __ipparse returns 0 on success and -1 on failure. also change the conditional in inet_addr to be consistent with other uses of __ipparse where only negative values are treated as failure.
2013-10-23fix inet_ptonSzabolcs Nagy-26/+19
* parse IPv4 dotted-decimal correctly (without strtoul, no leading zeros) * disallow single leading ':' in IPv6 address * allow at most 4 hex digits in IPv6 address (according to RFC 2373) * have enough hex fields in IPv4 mapped IPv6 address * disallow leading zeros in IPv4 mapped IPv6 address
2013-10-22fix __ipparse to parse the generic numbers-and-dots IPv4 format correctlySzabolcs Nagy-5/+12
* allow at most 4 parts * bounds check the parts correctly * disallow leading whitespace and sign * check the address family before falling back to IPv6
2013-10-22fix inet_aton to accept the generic "numbers-and-dots" IPv4 address formatSzabolcs Nagy-1/+4
2013-10-21split inet_addr and inet_ntoa back into their own filesRich Felker-16/+21
despite being practically deprecated, these functions are still part of the standard and thus cannot reside in a file that also contains namespace pollution. this reverts some of the changes made in commit e40f48a421a9176e3e298b5bac75f0355b219e58.
2013-10-19fix return value for inet_pton in ipv6 failure casesRich Felker-6/+6
in the case of input that does not match the expected form, the correct return value is 0, not -1.
2013-08-23fix regression in dn_expand/reverse dnsRich Felker-1/+1
off-by-one error copying the name components was yielding junk at the beginning and truncating one character at the end (of every component).
2013-08-14fix length computation in dn_expandRich Felker-3/+5
there are two possible points where the length is evaluated: either the first 'compression' jump, or the null terminator if no jumps have taken place yet. the previous code only measured the length of the first component.
2013-08-14de-duplicate dn_expand, fix return value and signature, clean upRich Felker-48/+23
the duplicate code in dn_expand and its incorrect return values are both results of the history of the code: the version in __dns.c was originally written with no awareness of the legacy resolver API, and was later copy-and-paste duplicated to provide the legacy API. this commit is the first of a series that will restructure the internal dns code to share as much code as possible with the legacy resolver API functions. I have also removed the loop detection logic, since the output buffer length limit naturally prevents loops. in order to avoid long runtime when encountering a loop if the caller provided a ridiculously long buffer, the caller-provided length is clamped at the maximum dns name length.
2013-07-25fix undefined strcpy call in inet_ntopRich Felker-1/+1
source and dest arguments for strcpy cannot overlap, so memmove must be used here. the length is already known from the above loop.
2013-07-25make inet_ntop format v4-mapped ipv6 addresses properlyRich Felker-8/+14
based on a patch by orc. POSIX actually fails to specify the format of the ntop conversion; presumably, any output that will correctly round-trip back via the (well-specified) pton operation is acceptable. the new behavior is much more convenient than the old, however. this patch also affects getnameinfo, which is implemented in terms of inet_ntop and which is the preferred interface for performing this conversion. I've also removed some inexplicable cruft (filling the buffer with 'x' before doing anything) whose origin I was unable to track down.
2013-07-24make getaddrinfo with AF_UNSPEC and null host return both IPv4 and v6Rich Felker-14/+23
based on a patch by orc, with indexing and flow control cleaned up a little bit. this code is all going to be replaced at some point in the near future.
2013-07-09fix missing SOCK_CLOEXEC in various functions that use sockets internallyRich Felker-4/+4
2013-07-01add stubs for additional legacy ether.h functionsRich Felker-0/+15
these would not be expensive to actually implement, but reading /etc/ethers does not sound like a particularly useful feature, so for now I'm leaving them as stubs.
2013-06-25implement inet_lnaof, inet_netof, and inet_makeaddrRich Felker-39/+55
also move all legacy inet_* functions into a single file to avoid wasting object file and compile time overhead on them. the added functions are legacy interfaces for working with classful ipv4 network addresses. they have no modern usefulness whatsoever, but some programs unconditionally use them anyway, and they're tiny.
2013-06-25add ether_aton[_r] and ether_ntoa[_r] functionsRich Felker-0/+43
based on patch by Strake with minor stylistic changes, and combined into a single file. this patch remained open for a long time due to some question as to whether ether_aton would be better implemented in terms of sscanf, and it's time something was committed, so here it is.
2013-04-09getifaddrs: implement proper ipv6 netmasksrofl0r-2/+11
2013-04-06getifaddrs: remove unused labelrofl0r-1/+0
2013-04-05getifaddrs: use if_nameindex to enumerate interfacesrofl0r-23/+9
2013-04-05getifaddrs: one less indent levelrofl0r-30/+28
2013-04-05getifaddrs: less mallocrofl0r-55/+52
2013-04-05add getifaddrsrofl0r-0/+191
supports ipv4 and ipv6, but not the "extended" usage where usage statistics and other info are assigned to ifa_data members of duplicate entries with AF_PACKET family.
2013-04-04implement dn_skipname (legacy resolver function)Rich Felker-0/+12
2013-02-02dynamically allocate storage for gethostby* buffersRich Felker-10/+32
this change shaves ~1k off libc.so bss size, and also avoids hard errors in the case where the static buffer was not large enough to hold the result. this whole framework is really ugly and might should be replaced or at least heavily overhauled when some changes/factorizations are made to getaddrinfo internals in the future.
2013-02-02fix blank ai_canonname from getaddrinfo for non-CNAMEsRich Felker-1/+1
2013-02-02fix memory leak due to double call to getaddrinfo in gethostbyname*Rich Felker-1/+0
2013-02-02fix error returns in gethostby*_r functionsRich Felker-17/+10
they're supposed to return an error code rather than using errno.
2012-12-19add inet_network (required for wine)rofl0r-0/+11
2012-11-05improve SOCK_NONBLOCK/SOCK_CLOEXEC fallback codeRich Felker-1/+2
checking for EINVAL should be sufficient, but qemu user emulation returns EPROTONOSUPPORT in some of the failure cases, and it seems conceivable that other kernels doing linux-emulation could make the same mistake. since DNS lookups and other important code might break if the fallback does not get invoked, be extra careful and check for either error. note that it's important NOT to perform the fallback code on other errors such as resource-exhaustion cases, since the fallback is not atomic and will lead to file-descriptor leaks in multi-threaded programs that use exec. the fallback code is only "safe" to run when the initial failure is caused by the application's choice of arguments, not the system state.
2012-09-29fix some more O_CLOEXEC/SOCK_CLOEXEC issuesRich Felker-3/+1
2012-09-29move accept4, dup3, and pipe2 to non-linux-specific locationsRich Felker-0/+9
these interfaces have been adopted by the Austin Group for inclusion in the next version of POSIX.