Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // Copyright (c) 2011 Google Inc. |
michael@0 | 2 | // All rights reserved. |
michael@0 | 3 | // |
michael@0 | 4 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 5 | // modification, are permitted provided that the following conditions are |
michael@0 | 6 | // met: |
michael@0 | 7 | // |
michael@0 | 8 | // * Redistributions of source code must retain the above copyright |
michael@0 | 9 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 10 | // * Redistributions in binary form must reproduce the above |
michael@0 | 11 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 12 | // in the documentation and/or other materials provided with the |
michael@0 | 13 | // distribution. |
michael@0 | 14 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 15 | // contributors may be used to endorse or promote products derived from |
michael@0 | 16 | // this software without specific prior written permission. |
michael@0 | 17 | // |
michael@0 | 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 29 | |
michael@0 | 30 | // Original author: Ted Mielczarek <ted.mielczarek@gmail.com> |
michael@0 | 31 | |
michael@0 | 32 | // dump_symbols_unittest.cc: |
michael@0 | 33 | // Unittests for google_breakpad::DumpSymbols |
michael@0 | 34 | |
michael@0 | 35 | #include <elf.h> |
michael@0 | 36 | #include <link.h> |
michael@0 | 37 | #include <stdio.h> |
michael@0 | 38 | |
michael@0 | 39 | #include <sstream> |
michael@0 | 40 | #include <vector> |
michael@0 | 41 | |
michael@0 | 42 | #include "breakpad_googletest_includes.h" |
michael@0 | 43 | #include "common/linux/synth_elf.h" |
michael@0 | 44 | #include "common/module.h" |
michael@0 | 45 | #include "common/using_std_string.h" |
michael@0 | 46 | |
michael@0 | 47 | namespace google_breakpad { |
michael@0 | 48 | bool ReadSymbolDataInternal(const uint8_t* obj_file, |
michael@0 | 49 | const string& obj_filename, |
michael@0 | 50 | const std::vector<string>& debug_dir, |
michael@0 | 51 | SymbolData symbol_data, |
michael@0 | 52 | Module** module); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | using google_breakpad::synth_elf::ELF; |
michael@0 | 56 | using google_breakpad::synth_elf::StringTable; |
michael@0 | 57 | using google_breakpad::synth_elf::SymbolTable; |
michael@0 | 58 | using google_breakpad::test_assembler::kLittleEndian; |
michael@0 | 59 | using google_breakpad::test_assembler::Section; |
michael@0 | 60 | using google_breakpad::Module; |
michael@0 | 61 | using google_breakpad::ReadSymbolDataInternal; |
michael@0 | 62 | using std::stringstream; |
michael@0 | 63 | using std::vector; |
michael@0 | 64 | using ::testing::Test; |
michael@0 | 65 | |
michael@0 | 66 | class DumpSymbols : public Test { |
michael@0 | 67 | public: |
michael@0 | 68 | void GetElfContents(ELF& elf) { |
michael@0 | 69 | string contents; |
michael@0 | 70 | ASSERT_TRUE(elf.GetContents(&contents)); |
michael@0 | 71 | ASSERT_LT(0U, contents.size()); |
michael@0 | 72 | |
michael@0 | 73 | elfdata_v.clear(); |
michael@0 | 74 | elfdata_v.insert(elfdata_v.begin(), contents.begin(), contents.end()); |
michael@0 | 75 | elfdata = &elfdata_v[0]; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | vector<uint8_t> elfdata_v; |
michael@0 | 79 | uint8_t* elfdata; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | TEST_F(DumpSymbols, Invalid) { |
michael@0 | 83 | Elf32_Ehdr header; |
michael@0 | 84 | memset(&header, 0, sizeof(header)); |
michael@0 | 85 | Module* module; |
michael@0 | 86 | EXPECT_FALSE(ReadSymbolDataInternal(reinterpret_cast<uint8_t*>(&header), |
michael@0 | 87 | "foo", |
michael@0 | 88 | vector<string>(), |
michael@0 | 89 | ALL_SYMBOL_DATA, |
michael@0 | 90 | &module)); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | TEST_F(DumpSymbols, SimplePublic32) { |
michael@0 | 94 | ELF elf(EM_386, ELFCLASS32, kLittleEndian); |
michael@0 | 95 | // Zero out text section for simplicity. |
michael@0 | 96 | Section text(kLittleEndian); |
michael@0 | 97 | text.Append(4096, 0); |
michael@0 | 98 | elf.AddSection(".text", text, SHT_PROGBITS); |
michael@0 | 99 | |
michael@0 | 100 | // Add a public symbol. |
michael@0 | 101 | StringTable table(kLittleEndian); |
michael@0 | 102 | SymbolTable syms(kLittleEndian, 4, table); |
michael@0 | 103 | syms.AddSymbol("superfunc", (uint32_t)0x1000, (uint32_t)0x10, |
michael@0 | 104 | ELF32_ST_INFO(STB_GLOBAL, STT_FUNC), |
michael@0 | 105 | SHN_UNDEF + 1); |
michael@0 | 106 | int index = elf.AddSection(".dynstr", table, SHT_STRTAB); |
michael@0 | 107 | elf.AddSection(".dynsym", syms, |
michael@0 | 108 | SHT_DYNSYM, // type |
michael@0 | 109 | SHF_ALLOC, // flags |
michael@0 | 110 | 0, // addr |
michael@0 | 111 | index, // link |
michael@0 | 112 | sizeof(Elf32_Sym)); // entsize |
michael@0 | 113 | |
michael@0 | 114 | elf.Finish(); |
michael@0 | 115 | GetElfContents(elf); |
michael@0 | 116 | |
michael@0 | 117 | Module* module; |
michael@0 | 118 | EXPECT_TRUE(ReadSymbolDataInternal(elfdata, |
michael@0 | 119 | "foo", |
michael@0 | 120 | vector<string>(), |
michael@0 | 121 | ALL_SYMBOL_DATA, |
michael@0 | 122 | &module)); |
michael@0 | 123 | |
michael@0 | 124 | stringstream s; |
michael@0 | 125 | module->Write(s, ALL_SYMBOL_DATA); |
michael@0 | 126 | EXPECT_EQ("MODULE Linux x86 000000000000000000000000000000000 foo\n" |
michael@0 | 127 | "PUBLIC 1000 0 superfunc\n", |
michael@0 | 128 | s.str()); |
michael@0 | 129 | delete module; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | TEST_F(DumpSymbols, SimplePublic64) { |
michael@0 | 133 | ELF elf(EM_X86_64, ELFCLASS64, kLittleEndian); |
michael@0 | 134 | // Zero out text section for simplicity. |
michael@0 | 135 | Section text(kLittleEndian); |
michael@0 | 136 | text.Append(4096, 0); |
michael@0 | 137 | elf.AddSection(".text", text, SHT_PROGBITS); |
michael@0 | 138 | |
michael@0 | 139 | // Add a public symbol. |
michael@0 | 140 | StringTable table(kLittleEndian); |
michael@0 | 141 | SymbolTable syms(kLittleEndian, 8, table); |
michael@0 | 142 | syms.AddSymbol("superfunc", (uint64_t)0x1000, (uint64_t)0x10, |
michael@0 | 143 | ELF64_ST_INFO(STB_GLOBAL, STT_FUNC), |
michael@0 | 144 | SHN_UNDEF + 1); |
michael@0 | 145 | int index = elf.AddSection(".dynstr", table, SHT_STRTAB); |
michael@0 | 146 | elf.AddSection(".dynsym", syms, |
michael@0 | 147 | SHT_DYNSYM, // type |
michael@0 | 148 | SHF_ALLOC, // flags |
michael@0 | 149 | 0, // addr |
michael@0 | 150 | index, // link |
michael@0 | 151 | sizeof(Elf64_Sym)); // entsize |
michael@0 | 152 | |
michael@0 | 153 | elf.Finish(); |
michael@0 | 154 | GetElfContents(elf); |
michael@0 | 155 | |
michael@0 | 156 | Module* module; |
michael@0 | 157 | EXPECT_TRUE(ReadSymbolDataInternal(elfdata, |
michael@0 | 158 | "foo", |
michael@0 | 159 | vector<string>(), |
michael@0 | 160 | ALL_SYMBOL_DATA, |
michael@0 | 161 | &module)); |
michael@0 | 162 | |
michael@0 | 163 | stringstream s; |
michael@0 | 164 | module->Write(s, ALL_SYMBOL_DATA); |
michael@0 | 165 | EXPECT_EQ("MODULE Linux x86_64 000000000000000000000000000000000 foo\n" |
michael@0 | 166 | "PUBLIC 1000 0 superfunc\n", |
michael@0 | 167 | s.str()); |
michael@0 | 168 | } |