summaryrefslogtreecommitdiffstats
path: root/libc/tzcode
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-04-25 14:02:59 -0700
committerElliott Hughes <enh@google.com>2013-04-25 14:02:59 -0700
commite7aaad8b832bdff3b88aa62b5c7597e5fd3db520 (patch)
tree7dcdc00044d95dfaca5dd4f0a87ba2050a050b50 /libc/tzcode
parent87efcd2e63c9f218f476ef88f21e660f9bce633f (diff)
downloadbionic-e7aaad8b832bdff3b88aa62b5c7597e5fd3db520.zip
bionic-e7aaad8b832bdff3b88aa62b5c7597e5fd3db520.tar.gz
bionic-e7aaad8b832bdff3b88aa62b5c7597e5fd3db520.tar.bz2
Improve diagnostics in the face of bad tzdata.
Bug: 8373554 Change-Id: If8df5e956105e01cce95221ff0a7fa9d2b474db3
Diffstat (limited to 'libc/tzcode')
-rw-r--r--libc/tzcode/localtime.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index 8a54e81..0c4d268 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -2276,14 +2276,18 @@ static int __bionic_open_tzdata_path(const char* path, const char* olson_id, int
int32_t data_offset;
int32_t zonetab_offset;
} header;
- if (TEMP_FAILURE_RETRY(read(fd, &header, sizeof(header))) != sizeof(header)) {
- fprintf(stderr, "%s: could not read header: %s\n", __FUNCTION__, strerror(errno));
+ memset(&header, 0, sizeof(header));
+ ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, &header, sizeof(header)));
+ if (bytes_read != sizeof(header)) {
+ fprintf(stderr, "%s: could not read header of \"%s\": %s\n",
+ __FUNCTION__, path, (bytes_read == -1) ? strerror(errno) : "short read");
close(fd);
return -1;
}
if (strncmp(header.tzdata_version, "tzdata", 6) != 0 || header.tzdata_version[11] != 0) {
- fprintf(stderr, "%s: bad magic: %s\n", __FUNCTION__, header.tzdata_version);
+ fprintf(stderr, "%s: bad magic in \"%s\": \"%.6s\"\n",
+ __FUNCTION__, path, header.tzdata_version);
close(fd);
return -1;
}
@@ -2296,7 +2300,8 @@ static int __bionic_open_tzdata_path(const char* path, const char* olson_id, int
#endif
if (TEMP_FAILURE_RETRY(lseek(fd, ntohl(header.index_offset), SEEK_SET)) == -1) {
- fprintf(stderr, "%s: couldn't seek to index: %s\n", __FUNCTION__, strerror(errno));
+ fprintf(stderr, "%s: couldn't seek to index in \"%s\": %s\n",
+ __FUNCTION__, path, strerror(errno));
close(fd);
return -1;
}
@@ -2330,11 +2335,14 @@ static int __bionic_open_tzdata_path(const char* path, const char* olson_id, int
}
if (TEMP_FAILURE_RETRY(lseek(fd, specific_zone_offset, SEEK_SET)) == -1) {
- fprintf(stderr, "%s: could not seek to %ld: %s\n", __FUNCTION__, specific_zone_offset, strerror(errno));
+ fprintf(stderr, "%s: could not seek to %ld in \"%s\": %s\n",
+ __FUNCTION__, specific_zone_offset, path, strerror(errno));
close(fd);
return -1;
}
+ // TODO: check that there's TZ_MAGIC at this offset, so we can fall back to the other file if not.
+
return fd;
}