[all-commits] [llvm/llvm-project] bf279f: [libc] Prevent printf index mode crashes

michaelrj-google via All-commits all-commits at lists.llvm.org
Wed Feb 22 16:27:39 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bf279f903b3f0e952d06af87d679ca7ae65234e3
      https://github.com/llvm/llvm-project/commit/bf279f903b3f0e952d06af87d679ca7ae65234e3
  Author: Michael Jones <michaelrj at google.com>
  Date:   2023-02-22 (Wed, 22 Feb 2023)

  Changed paths:
    M libc/src/stdio/printf_core/core_structs.h
    M libc/src/stdio/printf_core/parser.cpp
    M libc/src/stdio/printf_core/parser.h
    M libc/test/src/stdio/printf_core/parser_test.cpp

  Log Message:
  -----------
  [libc] Prevent printf index mode crashes

The posix standard defines an alternate mode for printf where the
conversions also have an index that describes which argument to select.
Due to how variadic arguments work in C, to reach the nth argument all
n-1 previous arguments must be read with their correct types. If the
format string does not specify the types for a continuous set of
arguments, then the arguments after the discontinuity cannot be safely
read. This patch causes all conversions requesting an argument that
comes after a gap be treated as raw (i.e. the conversion string is
printed literally).

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143782




More information about the All-commits mailing list