1. 13 12月, 2014 1 次提交
  2. 11 12月, 2014 4 次提交
  3. 04 12月, 2014 1 次提交
    • R
      fix getopt handling of ':' modifier for multibyte option characters · 014275b5
      Rich Felker 提交于
      the previous hard-coded offsets of +1 and +2 contained a hidden
      assumption that the option character matched was single-byte, despite
      this implementation of getopt attempting to support multibyte option
      characters. this patch reworks the matching logic to leave the final
      index pointing just past the matched character so that fixed offsets
      can be used to check for ':'.
      014275b5
  4. 03 12月, 2014 1 次提交
  5. 16 11月, 2014 1 次提交
    • F
      getopt: fix optional argument processing · acccc93e
      Felix Fietkau 提交于
      Processing an option character with optional argument fails if the
      option is last on the command line. This happens because the
      if (optind >= argc) check runs first before testing for optional
      argument.
      acccc93e
  6. 08 8月, 2014 1 次提交
  7. 31 7月, 2014 1 次提交
    • R
      implement ffsl and ffsll functions · ecc082c6
      Rich Felker 提交于
      per the resolution of Austin Group issue #617, these are accepted for
      XSI option in POSIX future and thus I'm treating them as standard
      functions.
      ecc082c6
  8. 20 7月, 2014 1 次提交
    • B
      add issetugid function to check for elevated privilege · ddddec10
      Brent Cook 提交于
      this function provides a way for third-party library code to use the
      same logic that's used internally in libc for suppressing untrusted
      input/state (e.g. the environment) when the application is running
      with privleges elevated by the setuid or setgid bit or some other
      mechanism. its semantics are intended to match the openbsd function by
      the same name.
      
      there was some question as to whether this function is necessary:
      getauxval(AT_SECURE) was proposed as an alternative. however, this has
      several drawbacks. the most obvious is that it asks programmers to be
      aware of an implementation detail of ELF-based systems (the aux
      vector) rather than simply the semantic predicate to be checked. and
      trying to write a safe, reliable version of issetugid in terms of
      getauxval is difficult. for example, early versions of the glibc
      getauxval did not report ENOENT, which could lead to false negatives
      if AT_SECURE was not present in the aux vector (this could probably
      only happen when running on non-linux kernels under linux emulation,
      since glibc does not support linux versions old enough to lack
      AT_SECURE). as for musl, getauxval has always properly reported
      errors, but prior to commit 7bece9c2,
      the musl implementation did not emulate AT_SECURE if missing, which
      would result in a false positive. since musl actually does partially
      support kernels that lack AT_SECURE, this was problematic.
      
      the intent is that library authors will use issetugid if its
      availability is detected at build time, and only fall back to the
      unreliable alternatives on systems that lack it.
      
      patch by Brent Cook. commit message/rationale by Rich Felker.
      ddddec10
  9. 18 7月, 2014 1 次提交
    • R
      provide getauxval(AT_SECURE) even if it is missing from the aux vector · 7bece9c2
      Rich Felker 提交于
      this could happen on 2.4-series linux kernels that predate AT_SECURE
      and possibly on other kernels that are emulating the linux syscall API
      but not providing AT_SECURE in the aux vector at startup.
      
      in principle applications should be checking errno anyway, but this
      does not really work. to be secure, the caller would have to treat
      ENOENT (indeterminate result) as possibly-suid and thereby disable
      functionality in the typical non-suid usage case. and since glibc only
      runs on kernels that provide AT_SECURE, applications written to the
      glibc getauxval API might simply assume it succeeds.
      7bece9c2
  10. 12 7月, 2014 4 次提交
    • R
      implement the LOG_CONS option in syslog · 781f26bc
      Rich Felker 提交于
      this was previously a no-op, somewhat intentionally, because I failed
      to understand that it only has an effect when sending to the logging
      facility fails and thus is not the nuisance that it would be if always
      sent output to the console.
      781f26bc
    • R
      suppress early syslog return when log socket cannot be opened · a64a045d
      Rich Felker 提交于
      this behavior is no longer valid in general, and was never necessary.
      if the LOG_PERROR option is set, output to stderr could still succeed.
      also, when the LOG_CONS option is added, it will need syslog to
      proceed even if opening the log socket fails.
      a64a045d
    • R
      implement the LOG_PERROR option in syslog · b8c4cf61
      Rich Felker 提交于
      this is a nonstandard feature, but easy and inexpensive to add. since
      the corresponding macro has always been defined in our syslog.h, it
      makes sense to actually support it. applications may reasonably be
      using the presence of the macro to assume that the feature is
      supported.
      
      the behavior of omitting the 'header' part of the log message does not
      seem to be well-documented, but matches other implementations (at
      least glibc) which have this option.
      
      based on a patch by Clément Vasseur, but simplified using %n.
      b8c4cf61
    • C
      fix the %m specifier in syslog · da271181
      Clément Vasseur 提交于
      errno must be saved upon vsyslog entry, otherwise its value could be
      changed by some libc function before reaching the %m handler in
      vsnprintf.
      da271181
  11. 22 6月, 2014 1 次提交
    • R
      implement fmtmsg function · 5474a346
      Rich Felker 提交于
      contributed by Isaac Dunham. this seems to be the last interface that
      was missing for complete POSIX 2008 base + XSI coverage.
      5474a346
  12. 12 6月, 2014 1 次提交
  13. 30 5月, 2014 1 次提交
    • S
      fix for broken kernel side RLIM_INFINITY on mips · 8258014f
      Szabolcs Nagy 提交于
      On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and
      this is the definition in the userspace api), but since it is in
      the middle of the valid range of limits and limits are often
      compared with relational operators, various kernel side logic is
      broken if larger than -1UL/2 limits are used. So we truncate the
      limits to -1UL/2 in get/setrlimit and prlimit.
      
      Even if the kernel side logic consistently treated -1UL/2 as greater
      than any other limit value, there wouldn't be any clean workaround
      that allowed using large limits:
      * using -1UL/2 as RLIM_INFINITY in userspace would mean different
      infinity value for get/setrlimt and prlimit (where infinity is always
      -1ULL) and userspace logic could break easily (just like the kernel
      is broken now) and more special case code would be needed for mips.
      * translating -1UL/2 kernel side value to -1ULL in userspace would
      mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed
      to the kernel instead).
      8258014f
  14. 25 5月, 2014 1 次提交
    • R
      support kernels with no SYS_open syscall, only SYS_openat · 594c827a
      Rich Felker 提交于
      open is handled specially because it is used from so many places, in
      so many variants (2 or 3 arguments, setting errno or not, and
      cancellable or not). trying to do it as a function would not only
      increase bloat, but would also risk subtle breakage.
      
      this is the first step towards supporting "new" archs where linux
      lacks "old" syscalls.
      594c827a
  15. 07 4月, 2014 1 次提交
    • R
      add getauxval function · 21ada94c
      Rich Felker 提交于
      in a sense this implementation is incomplete since it doesn't provide
      the HWCAP_* macros for use with AT_HWCAP, which is perhaps the most
      important intended usage case for getauxval. they will be added at a
      later time.
      21ada94c
  16. 19 3月, 2014 1 次提交
    • R
      use syscall_arg_t for arguments in public syscall() function · 5f95f965
      Rich Felker 提交于
      on x32, this change allows programs which use syscall() with pointers
      or 64-bit values as arguments to work correctly, i.e. without
      truncation or incorrect sign extension. on all other supported archs,
      syscall_arg_t is defined as long, so this change is a no-op.
      5f95f965
  17. 17 3月, 2014 1 次提交
    • R
      fix negated error codes from ptsname_r · 66193171
      Rich Felker 提交于
      the incorrect error codes also made their way into errno when
      __ptsname_r was called by plain ptsname, which reports errors via
      errno rather than a return value.
      66193171
  18. 02 2月, 2014 1 次提交
    • R
      fix nftw FTW_MOUNT flag · 73871ee3
      Rich Felker 提交于
      the incorrect check for crossing device boundaries was preventing nftw
      from traversing anything except the initially provided pathname.
      73871ee3
  19. 13 12月, 2013 1 次提交
    • R
      optimize get_current_dir_name to reduce stack bloat · 2b7cf6db
      Rich Felker 提交于
      our getcwd already (as an extension) supports allocation of a buffer
      when the buffer argument is a null pointer, so there's no need to
      duplicate the allocation logic in this wrapper function. duplicating
      it is actually harmful in that it doubles the stack usage from
      PATH_MAX to 2*PATH_MAX.
      2b7cf6db
  20. 12 12月, 2013 1 次提交
  21. 23 11月, 2013 4 次提交
    • R
      fix and refactor child reaping logic in wordexp · aeea71dc
      Rich Felker 提交于
      loop condition was incorrect and confusing and caused an infinite loop
      when (broken) applications reaped the pid from a signal handler or
      another thread before wordexp's call to waitpid could do so.
      aeea71dc
    • R
      caaf7d44
    • R
      fix resource exhaustion and zero-word cases in wordexp · 8253f59e
      Rich Felker 提交于
      when WRDE_NOSPACE is returned, the we_wordv and we_wordc members must
      be valid, because the interface contract allows them to return partial
      results.
      
      in the case of zero results (due either to resource exhaustion or a
      zero-word input) the we_wordv array still should contain a terminating
      null pointer and the initial we_offs null pointers. this is impossible
      on resource exhaustion, so a correct application must presumably check
      for a null pointer in we_wordv; POSIX however seems to ignore the
      issue. the previous code may have crashed under this situation.
      8253f59e
    • R
      improve robustness of wordexp and fix handling of 0-word case · d8f1908b
      Rich Felker 提交于
      avoid using exit status to determine if a shell error occurred, since
      broken programs may install SIGCHLD handlers which reap all zombies,
      including ones that don't belong to them. using clone and __WCLONE
      does not seem to work for avoiding this problem since exec resets the
      exit signal to SIGCHLD.
      
      instead, the new code uses a dummy word at the beginning of the
      shell's output, which is ignored, to determine whether the command was
      executed successfully. this also fixes a corner case where a word
      string containing zero words was interpreted as a single zero-length
      word rather than no words at all. POSIX does not seem to require this
      case to be supported anyway, though.
      
      in addition, the new code uses the correct retry idiom for waitpid to
      ensure that spurious STOP/CONT signals in the child and/or EINTR in
      the parent do not prevent successful wait for the child, and blocks
      signals in the child.
      d8f1908b
  22. 01 9月, 2013 3 次提交
    • R
      remove incorrect cancellation points from realpath · 35e8621a
      Rich Felker 提交于
      35e8621a
    • R
      debloat realpath's allocation strategy · dfddd432
      Rich Felker 提交于
      rather than allocating a PATH_MAX-sized buffer when the caller does
      not provide an output buffer, work first with a PATH_MAX-sized temp
      buffer with automatic storage, and either copy it to the caller's
      buffer or strdup it on success. this not only avoids massive memory
      waste, but also avoids pulling in free (and thus the full malloc
      implementation) unnecessarily in static programs.
      dfddd432
    • R
      make realpath use O_PATH when opening the file · 27b4923b
      Rich Felker 提交于
      this avoids failure if the file is not readable and avoids odd
      behavior for device nodes, etc. on old kernels that lack O_PATH, the
      old behavior (O_RDONLY) will naturally happen as the fallback.
      27b4923b
  23. 03 8月, 2013 1 次提交
  24. 06 4月, 2013 1 次提交
    • I
      Add ABI compatability aliases. · 14f0272e
      Isaac Dunham 提交于
      GNU used several extensions that were incompatible with C99 and POSIX,
      so they used alternate names for the standard functions.
      
      The result is that we need these to run standards-conformant programs
      that were linked with glibc.
      14f0272e
  25. 01 4月, 2013 1 次提交
  26. 24 3月, 2013 1 次提交
    • R
      fix multiple bugs in syslog interfaces · 427c0ca7
      Rich Felker 提交于
      1. as reported by William Haddon, the value returned by snprintf was
      wrongly used as a length passed to sendto, despite it possibly
      exceeding the buffer length. this could lead to invalid reads and
      leaking additional data to syslog.
      
      2. openlog was storing a pointer to the ident string passed by the
      caller, rather than copying it. this bug is shared with (and even
      documented in) other implementations like glibc, but such behavior
      does not seem to meet the requirements of the standard.
      
      3. extremely long ident provided to openlog, or corrupt ident due to
      the above issue, could possibly have resulted in buffer overflows.
      despite having the potential for smashing the stack, i believe the
      impact is low since ident points to a short string literal in typical
      application usage (and per the above bug, other usages will break
      horribly on other implementations).
      
      4. when used with LOG_NDELAY, openlog was not connecting the
      newly-opened socket; sendto was being used instead. this defeated the
      main purpose of LOG_NDELAY: preparing for chroot.
      
      5. the default facility was not being used at all, so all messages
      without an explicit facility passed to syslog were getting logged at
      the kernel facility.
      
      6. setlogmask was not thread-safe; no synchronization was performed
      updating the mask. the fix uses atomics rather than locking to avoid
      introducing a lock in the fast path for messages whose priority is not
      in the mask.
      
      7. in some code paths, the syslog lock was being unlocked twice; this
      could result in releasing a lock that was actually held by a different
      thread.
      
      some additional enhancements to syslog such as a default identifier
      based on argv[0] or similar may still be desired; at this time, only
      the above-listed bugs have been fixed.
      427c0ca7
  27. 08 12月, 2012 2 次提交
  28. 07 12月, 2012 1 次提交