Skip to content
Snippets Groups Projects
  • Duncan P. N. Exon Smith's avatar
    839cd13b
    Lex: Never overflow the file in HeaderMap::lookupFilename() · 839cd13b
    Duncan P. N. Exon Smith authored
    If a header map file is corrupt, the strings in the string table may not
    be null-terminated.  The logic here previously relied on `MemoryBuffer`
    always being null-terminated, but this isn't actually guaranteed by the
    class AFAICT.  Moreover, we're seeing a lot of crash traces at calls to
    `strlen()` inside of `lookupFilename()`, so something is going wrong
    there.
    
    Instead, use `strnlen()` to get the length, and check for corruption.
    
    Also remove code paths that could call `StringRef(nullptr)`.  r261459
    made these rather obvious (although they'd been there all along).
    
    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261461 91177308-0d34-0410-b5e6-96231b3b80d8
    839cd13b
    History
    Lex: Never overflow the file in HeaderMap::lookupFilename()
    Duncan P. N. Exon Smith authored
    If a header map file is corrupt, the strings in the string table may not
    be null-terminated.  The logic here previously relied on `MemoryBuffer`
    always being null-terminated, but this isn't actually guaranteed by the
    class AFAICT.  Moreover, we're seeing a lot of crash traces at calls to
    `strlen()` inside of `lookupFilename()`, so something is going wrong
    there.
    
    Instead, use `strnlen()` to get the length, and check for corruption.
    
    Also remove code paths that could call `StringRef(nullptr)`.  r261459
    made these rather obvious (although they'd been there all along).
    
    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261461 91177308-0d34-0410-b5e6-96231b3b80d8
Code owners
Assign users and groups as approvers for specific file changes. Learn more.