Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: base/third_party/symbolize/symbolize.cc

Issue 2566623003: Fixed google::FindSymbol reading past end of a section (Closed)
Patch Set: Use std::min Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006, Google Inc. 1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // macro to add platform specific defines (e.g. OS_OPENBSD). 49 // macro to add platform specific defines (e.g. OS_OPENBSD).
50 50
51 #ifdef GLOG_BUILD_CONFIG_INCLUDE 51 #ifdef GLOG_BUILD_CONFIG_INCLUDE
52 #include GLOG_BUILD_CONFIG_INCLUDE 52 #include GLOG_BUILD_CONFIG_INCLUDE
53 #endif // GLOG_BUILD_CONFIG_INCLUDE 53 #endif // GLOG_BUILD_CONFIG_INCLUDE
54 54
55 #include "utilities.h" 55 #include "utilities.h"
56 56
57 #if defined(HAVE_SYMBOLIZE) 57 #if defined(HAVE_SYMBOLIZE)
58 58
59 #include <algorithm>
59 #include <limits> 60 #include <limits>
60 61
61 #include "symbolize.h" 62 #include "symbolize.h"
62 #include "demangle.h" 63 #include "demangle.h"
63 64
64 _START_GOOGLE_NAMESPACE_ 65 _START_GOOGLE_NAMESPACE_
65 66
66 // We don't use assert() since it's not guaranteed to be 67 // We don't use assert() since it's not guaranteed to be
67 // async-signal-safe. Instead we define a minimal assertion 68 // async-signal-safe. Instead we define a minimal assertion
68 // macro. So far, we don't need pretty printing for __FILE__, etc. 69 // macro. So far, we don't need pretty printing for __FILE__, etc.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // 32 elements (to keep stack consumption low), otherwise we can 290 // 32 elements (to keep stack consumption low), otherwise we can
290 // have a 64 element Elf32_Sym array. 291 // have a 64 element Elf32_Sym array.
291 #if __WORDSIZE == 64 292 #if __WORDSIZE == 64
292 #define NUM_SYMBOLS 32 293 #define NUM_SYMBOLS 32
293 #else 294 #else
294 #define NUM_SYMBOLS 64 295 #define NUM_SYMBOLS 64
295 #endif 296 #endif
296 297
297 // Read at most NUM_SYMBOLS symbols at once to save read() calls. 298 // Read at most NUM_SYMBOLS symbols at once to save read() calls.
298 ElfW(Sym) buf[NUM_SYMBOLS]; 299 ElfW(Sym) buf[NUM_SYMBOLS];
299 const ssize_t len = ReadFromOffset(fd, &buf, sizeof(buf), offset); 300 int num_symbols_to_read = std::min(NUM_SYMBOLS, num_symbols - i);
301 const ssize_t len =
302 ReadFromOffset(fd, &buf, sizeof(buf[0]) * num_symbols_to_read, offset);
300 SAFE_ASSERT(len % sizeof(buf[0]) == 0); 303 SAFE_ASSERT(len % sizeof(buf[0]) == 0);
301 const ssize_t num_symbols_in_buf = len / sizeof(buf[0]); 304 const ssize_t num_symbols_in_buf = len / sizeof(buf[0]);
302 SAFE_ASSERT(num_symbols_in_buf <= sizeof(buf)/sizeof(buf[0])); 305 SAFE_ASSERT(num_symbols_in_buf <= num_symbols_to_read);
303 for (int j = 0; j < num_symbols_in_buf; ++j) { 306 for (int j = 0; j < num_symbols_in_buf; ++j) {
304 const ElfW(Sym)& symbol = buf[j]; 307 const ElfW(Sym)& symbol = buf[j];
305 uint64_t start_address = symbol.st_value; 308 uint64_t start_address = symbol.st_value;
306 start_address += symbol_offset; 309 start_address += symbol_offset;
307 uint64_t end_address = start_address + symbol.st_size; 310 uint64_t end_address = start_address + symbol.st_size;
308 if (symbol.st_value != 0 && // Skip null value symbols. 311 if (symbol.st_value != 0 && // Skip null value symbols.
309 symbol.st_shndx != 0 && // Skip undefined symbols. 312 symbol.st_shndx != 0 && // Skip undefined symbols.
310 start_address <= pc && pc < end_address) { 313 start_address <= pc && pc < end_address) {
311 ssize_t len1 = ReadFromOffset(fd, out, out_size, 314 ssize_t len1 = ReadFromOffset(fd, out, out_size,
312 strtab->sh_offset + symbol.st_name); 315 strtab->sh_offset + symbol.st_name);
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 864
862 // TODO: Support other environments. 865 // TODO: Support other environments.
863 bool Symbolize(void *pc, char *out, int out_size) { 866 bool Symbolize(void *pc, char *out, int out_size) {
864 assert(0); 867 assert(0);
865 return false; 868 return false;
866 } 869 }
867 870
868 _END_GOOGLE_NAMESPACE_ 871 _END_GOOGLE_NAMESPACE_
869 872
870 #endif 873 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698