summaryrefslogtreecommitdiffstats
path: root/libc/tzcode
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-03-14 14:38:08 -0700
committerElliott Hughes <enh@google.com>2013-03-14 14:38:08 -0700
commite0175ca7e440a87e9d03f249fc8f210063df7908 (patch)
tree982e64580d19fc846cd7f2a1fa1dee2fbe2274d8 /libc/tzcode
parentec706c24acb4d1db6a583a57b76adfb9250d39eb (diff)
downloadbionic-e0175ca7e440a87e9d03f249fc8f210063df7908.zip
bionic-e0175ca7e440a87e9d03f249fc8f210063df7908.tar.gz
bionic-e0175ca7e440a87e9d03f249fc8f210063df7908.tar.bz2
Don't search off the end of the index for bad Olson ids.
In the old code, the index was a file to itself, so it made sense to read until you hit the end of the file. In the new code, the index is followed by hundreds of KiB of data, so we need to just search the index. Bug: 8368791 Change-Id: Icf5f8b5516cf3a93679fa849c9f6cd1cb100e0f1
Diffstat (limited to 'libc/tzcode')
-rw-r--r--libc/tzcode/localtime.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index 689bbd3..8a54e81 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -2305,7 +2305,13 @@ static int __bionic_open_tzdata_path(const char* path, const char* olson_id, int
static const size_t NAME_LENGTH = 40;
unsigned char buf[NAME_LENGTH + 3 * sizeof(int32_t)];
- while (TEMP_FAILURE_RETRY(read(fd, buf, sizeof(buf))) == (ssize_t) sizeof(buf)) {
+
+ size_t id_count = (ntohl(header.data_offset) - ntohl(header.index_offset)) / sizeof(buf);
+ for (size_t i = 0; i < id_count; ++i) {
+ if (TEMP_FAILURE_RETRY(read(fd, buf, sizeof(buf))) != (ssize_t) sizeof(buf)) {
+ break;
+ }
+
char this_id[NAME_LENGTH + 1];
memcpy(this_id, buf, NAME_LENGTH);
this_id[NAME_LENGTH] = '\0';