1. 10 6月, 2014 2 次提交
    • R
      replace all remaining internal uses of pthread_self with __pthread_self · df15168c
      Rich Felker 提交于
      prior to version 1.1.0, the difference between pthread_self (the
      public function) and __pthread_self (the internal macro or inline
      function) was that the former would lazily initialize the thread
      pointer if it was not already initialized, whereas the latter would
      crash in this case. since lazy initialization is no longer supported,
      use of pthread_self no longer makes sense; it simply generates larger,
      slower code.
      df15168c
    • R
      add thread-pointer support for pre-2.6 kernels on i386 · 64e32287
      Rich Felker 提交于
      such kernels cannot support threads, but the thread pointer is also
      important for other purposes, most notably stack protector. without a
      valid thread pointer, all code compiled with stack protector will
      crash. the same applies to any use of thread-local storage by
      applications or libraries.
      
      the concept of this patch is to fall back to using the modify_ldt
      syscall, which has been around since linux 1.0, to setup the gs
      segment register. since the kernel does not have a way to
      automatically assign ldt entries, use of slot zero is hard-coded. if
      this fallback path is used, __set_thread_area returns a positive value
      (rather than the usual zero for success, or negative for error)
      indicating to the caller that the thread pointer was successfully set,
      but only for the main thread, and that thread creation will not work
      properly. the code in __init_tp has been changed accordingly to record
      this result for later use by pthread_create.
      64e32287
  2. 07 6月, 2014 10 次提交
    • R
      avoid spurious lookup failures from badly-behaved nameservers · 246e752d
      Rich Felker 提交于
      the results of a dns query, whether it's performed as part of one of
      the standard name-resolving functions or directly by res_send, should
      be a function of the query, not of the particular nameserver that
      responds to it. thus, all responses which indicate a failure or
      refusal by the nameserver, as opposed to a positive or negative result
      for the query, should be ignored.
      
      the strategy used is to re-issue the query immediately (but with a
      limit on the number of retries, in case the server is really broken)
      when a response code of 2 (server failure, typically transient) is
      seen, and otherwise take no action on bad responses (which generally
      indicate a misconfigured nameserver or one which the client does not
      have permission to use), allowing the normal retry interval to apply
      and of course accepting responses from other nameservers queried in
      parallel.
      
      empirically this matches the traditional resolver behavior for
      nameservers that respond with a code of 2 in the case where there is
      just a single nameserver configured. the behavior diverges when
      multiple nameservers are available, since musl is querying them in
      parallel. in this case we are mildly more aggressive at retrying.
      246e752d
    • R
      use default timezone from /etc/localtime if $TZ is unset/blank · f6162949
      Rich Felker 提交于
      the way this is implemented, it also allows explicit setting of
      TZ=/etc/localtime even for suid programs. this is not a problem
      because /etc/localtime is a trusted path, much like the trusted
      zoneinfo search path.
      f6162949
    • R
      release 1.1.2 · 3ff3a1d5
      Rich Felker 提交于
      3ff3a1d5
    • T
      implement %y and %C specifiers in strptime · 348fc556
      Timo Teräs 提交于
      348fc556
    • R
      avoid invalid use of va_arg in open · 9c2d437c
      Rich Felker 提交于
      reading the variadic mode argument is only valid when the O_CREAT flag
      is present. this probably does not matter, but is needed for formal
      correctness, and could affect LTO or other full-program analysis.
      9c2d437c
    • R
      add O_CLOEXEC fallback for open and related functions · 7765706c
      Rich Felker 提交于
      since there is no easy way to detect whether open honored or ignored
      the O_CLOEXEC flag, the optimal solution to providing a fallback is
      simply to make the fcntl syscall to set the close-on-exec flag
      immediately after open returns.
      7765706c
    • R
      optimize SOCK_CLOEXEC fallback for socket function · 1cacc01d
      Rich Felker 提交于
      the fcntl function is heavy, so make the syscall directly instead.
      also, avoid the code size and runtime overhead of querying the old
      flags, since it's reasonable to assume nothing will be set on a
      newly-created socket. this code is only used on old kernels which lack
      proper atomic close-on-exec support, so future changes that might
      invalidate such an assumption do not need to be considered.
      1cacc01d
    • R
      add SOCK_CLOEXEC fallback for socketpair on old kernels · 1d348566
      Rich Felker 提交于
      as usual, this is non-atomic, but better than producing an error or
      failing to set the close-on-exec flag at all.
      1d348566
    • S
      implement dn_comp RFC 1035 domain name compression · abce3156
      Szabolcs Nagy 提交于
      the input name is validated, the other parameters are assumed to be
      valid (the list of already compressed names are not checked for
      infinite reference loops or out-of-bound offsets).
      
      names are handled case-sensitively for now.
      abce3156
    • S
      accept trailing . and empty domain names · 07355f50
      Szabolcs Nagy 提交于
      trailing . should be accepted in domain name strings by convention
      (RFC 1034), host name lookup accepts "." but rejects empty "", res_*
      interfaces also accept empty name following existing practice.
      07355f50
  3. 06 6月, 2014 5 次提交
  4. 05 6月, 2014 2 次提交
  5. 04 6月, 2014 4 次提交
    • R
      remove some dummy "ent" function aliases that duplicated real ones · 934aa135
      Rich Felker 提交于
      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.
      934aa135
    • R
      simplify vasprintf implementation · 6a25313c
      Rich Felker 提交于
      the old implementation preallocated a buffer in order to try to avoid
      calling vsnprintf more than once. not only did this potentially lead
      to memory fragmentation from trimming with realloc; it also pulled in
      realloc/free, which otherwise might not be needed in a static linked
      program.
      6a25313c
    • R
      add support for ipv6 scope_id to getaddrinfo and getnameinfo · bdad2fef
      Rich Felker 提交于
      for all address types, a scope_id specified as a decimal value is
      accepted. for addresses with link-local scope, a string containing the
      interface name is also accepted.
      
      some changes are made to error handling to avoid unwanted fallbacks in
      the case where the scope_id is invalid: if an earlier name lookup
      backend fails with an error rather than simply "0 results", this
      failure now suppresses any later attempts with other backends.
      
      in getnameinfo, a light "itoa" type function is added for generating
      decimal scope_id results, and decimal port strings for services are
      also generated using this function now so as not to pull in the
      dependency on snprintf.
      
      in netdb.h, a definition for the NI_NUMERICSCOPE flag is added. this
      is required by POSIX (it was previously missing) and needed to allow
      callers to suppress interface-name lookups.
      bdad2fef
    • R
      fix if_nametoindex return value when interface does not exist · 8041af59
      Rich Felker 提交于
      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.
      8041af59
  6. 03 6月, 2014 3 次提交
    • R
      fix negative response and non-response handling for dns queries · d85d261e
      Rich Felker 提交于
      previously, all failures to obtain at least one address were treated
      as nonexistant names (EAI_NONAME). this failed to account for the
      possibility of transient failures (no response at all, or a response
      with rcode of 2, server failure) or permanent failures that do not
      indicate the nonexistence of the requested name. only an rcode of 3
      should be treated as an indication of nonexistence.
      d85d261e
    • R
      fix some validation checks in dns response parsing code · ac2a7893
      Rich Felker 提交于
      since the buffer passed always has an actual size of 512 bytes, the
      maximum possible response packet size, no out-of-bounds access was
      possible; however, reading past the end of the valid portion of the
      packet could cause the parser to attempt to process junk as answer
      content.
      ac2a7893
    • R
      fix incorrect end pointer in some cases when wcsrtombs stops early · 8fba4458
      Rich Felker 提交于
      when wcsrtombs stopped due to hitting zero remaining space in the
      output buffer, it was wrongly clearing the position pointer as if it
      had completed the conversion successfully.
      
      this commit rearranges the code somewhat to make a clear separation
      between the cases of ending due to running out of output buffer space,
      and ending due to reaching the end of input or an illegal sequence in
      the input. the new branches have been arranged with the hope of
      optimizing more common cases, too.
      8fba4458
  7. 02 6月, 2014 6 次提交
    • R
      remove cruft from old resolver and numeric ip parsing · 76f440cf
      Rich Felker 提交于
      the old resolver code used a function __ipparse which contained the
      logic for inet_addr and inet_aton, which is needed in getaddrinfo.
      this was phased out in the resolver overhaul in favor of directly
      using inet_aton and inet_pton as appropriate.
      
      this commit cleans up some stuff that was left behind.
      76f440cf
    • R
      switch standard resolver functions to use the new dns backend · 33301980
      Rich Felker 提交于
      this is the third phase of the "resolver overhaul" project.
      
      this commit removes all of the old dns code, and switches the
      __lookup_name backend (used by getaddrinfo, etc.) and the getnameinfo
      function to use the newly implemented __res_mkquery and __res_msend
      interfaces. for parsing the results, a new callback-based __dns_parse
      function, based on __dns_get_rr from the old dns code, is used.
      33301980
    • R
      a2a328bd
    • R
      implement new dns backend, res_send and other legacy resolver functions · 8312f7f6
      Rich Felker 提交于
      this is the second phase of the "resolver overhaul" project.
      
      the key additions in this commit are the __res_msend and __res_mkquery
      functions, which have been factored so as to provide a backend for
      both the legacy res_* functions and the standard getaddrinfo and
      getnameinfo functions. the latter however are still using the old
      backend code; there is code duplication which still needs to be
      removed, and this will be the next phase of the resolver overhaul.
      
      __res_msend is derived from the old __dns_doqueries function, but
      generalized to send arbitrary caller-provided packets in parallel
      rather than producing the parallel queries itself. this allows it to
      be used (completely trivially) as a backend for res_send. the
      factored-out query generation code, with slightly more generality, is
      now part of __res_mkquery.
      8312f7f6
    • T
      add ipsec and tunneling protocols to getprotoent-family functions · 1871f583
      Timo Teräs 提交于
      iptables and ipsec-tools among others require these to function
      properly.
      1871f583
    • R
      fix off-by-one in checking hostname length in new resolver backend · bb9af59b
      Rich Felker 提交于
      this bug was introduced in the recent resolver overhaul commits. it
      likely had visible symptoms. these were probably limited to wrongly
      accepting truncated versions of over-long names (vs rejecting them),
      as opposed to stack-based overflows or anything more severe, but no
      extensive checks were made. there have been no releases where this bug
      was present.
      bb9af59b
  8. 01 6月, 2014 3 次提交
    • R
      improve getservbyname_r using new resolver backend · af7c308e
      Rich Felker 提交于
      now that host and service lookup have been separated in the backend,
      there's no need for service lookup functions to pull in the host
      lookup code. moreover, dynamic allocation is no longer needed, so this
      function should now be async-signal-safe. it's also significantly
      smaller.
      
      one change in getservbyname is also made: knowing that getservbyname_r
      needs only two character pointers in the caller-provided buffer, some
      wasted bss can be avoided.
      af7c308e
    • R
      improve gethostbyname2_r using new resolver backend · e8f39ca4
      Rich Felker 提交于
      these changes reduce the size of the function somewhat and remove many
      of its dependencies, including free. in principle it should now be
      async-signal-safe, but this has not been verified in detail.
      
      minor changes to error handling are also made.
      e8f39ca4
    • R
      refactor getaddrinfo and add support for most remaining features · 6f409bff
      Rich Felker 提交于
      this is the first phase of the "resolver overhaul" project.
      
      conceptually, the results of getaddrinfo are a direct product of a
      list of address results and a list of service results. the new code
      makes this explicit by computing these lists separately and combining
      the results. this adds support for services that have both tcp and udp
      versions, where the caller has not specified which it wants, and
      eliminates a number of duplicate code paths which were all producing
      the final output addrinfo structures, but in subtly different ways,
      making it difficult to implement any of the features which were
      missing.
      
      in addition to the above benefits, the refactoring allows for legacy
      functions like gethostbyname to be implemented without using the
      getaddrinfo function itself. such changes to the legacy functions have
      not yet been made, however.
      
      further improvements include matching of service alias names from
      /etc/services (previously only the primary name was supported),
      returning multiple results from /etc/hosts (previously only the first
      matching line was honored), and support for the AI_V4MAPPED and AI_ALL
      flags.
      
      features which remain unimplemented are IDN translations (encoding
      non-ASCII hostnames for DNS lookup) and the AI_ADDRCONFIG flag.
      
      at this point, the DNS-based name resolving code is still based on the
      old interfaces in __dns.c, albeit somewhat simpler in its use of them.
      there may be some dead code which could already be removed, but
      changes to this layer will be a later phase of the resolver overhaul.
      6f409bff
  9. 31 5月, 2014 5 次提交
    • S
      fix POSIX namespace pollution in sys/types.h · 5f4c4966
      Szabolcs Nagy 提交于
      int8_t, u_int8_t, etc types are moved under _BSD_SOURCE
      5f4c4966
    • S
      use cleaner code for handling float rounding in vfprintf · bff6095d
      Szabolcs Nagy 提交于
      CONCAT(0x1p,LDBL_MANT_DIG) is not safe outside of libc,
      use 2/LDBL_EPSILON instead.
      
      fix was proposed by Morten Welinder.
      bff6095d
    • S
      update netinet/in.h to match the current kernel uapi · c3504686
      Szabolcs Nagy 提交于
      from linux/in.h and linux/in6.h uapi headers the following
      missing socket options were added:
      
      IP_NODEFRAG - used with customized ipv4 headers
      IPV6_RECVPATHMTU - for ipv6 path mtu
      IPV6_PATHMTU - for ipv6 path mtu
      IPV6_DONTFRAG - for ipv6 path mtu
      IPV6_ADDR_PREFERENCES - RFC5014 Source Address Selection
      IPV6_MINHOPCOUNT - RFC5082 Generalized TTL Security Mechanism
      IPV6_ORIGDSTADDR - used by tproxy
      IPV6_RECVORIGDSTADDR - used by tproxy
      IPV6_TRANSPARENT - used by tproxy
      IPV6_UNICAST_IF - ipv6 version of IP_UNICAST_IF
      
      and socket option values:
      
      IP_PMTUDISC_OMIT - value for IP_MTU_DISCOVER option, new in linux 3.14
      IPV6_PMTUDISC_OMIT - same for IPV6_MTU_DISCOVER
      IPV6_PMTUDISC_INTERFACE - ipv6 version of IP_PMTUDISC_INTERFACE
      IPV6_PREFER_* - flags for IPV6_ADDR_PREFERENCES
      
      not added: ipv6 flow info and flow label related definitions.
      (it's unclear if libc should define these and namespace polluting
      type name is involved so they are not provided for now)
      c3504686
    • S
      add SO_BPF_EXTENSIONS socket option · c8ea2126
      Szabolcs Nagy 提交于
      this was introduced to query BPF extension support with getsockopt
      in linux 3.14, commit ea02f9411d9faa3553ed09ce0ec9f00ceae9885e
      c8ea2126
    • S
      add sched_{get,set}attr syscall numbers and SCHED_DEADLINE macro · fd9571e2
      Szabolcs Nagy 提交于
      linux 3.14 introduced sched_getattr and sched_setattr syscalls in
      commit d50dde5a10f305253cbc3855307f608f8a3c5f73
      
      and the related SCHED_DEADLINE scheduling policy in
      commit aab03e05e8f7e26f51dee792beddcb5cca9215a5
      
      but struct sched_attr "extended scheduling parameters data structure"
      is not yet exported to userspace (necessary for using the syscalls)
      so related uapi definitions are not added yet.
      fd9571e2