diff options
-rw-r--r-- | trace-input.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/trace-input.c b/trace-input.c index f537ef5..723d47f 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -92,6 +92,7 @@ struct tracecmd_input { | |||
92 | size_t header_files_start; | 92 | size_t header_files_start; |
93 | size_t ftrace_files_start; | 93 | size_t ftrace_files_start; |
94 | size_t event_files_start; | 94 | size_t event_files_start; |
95 | size_t total_file_size; | ||
95 | }; | 96 | }; |
96 | 97 | ||
97 | __thread struct tracecmd_input *tracecmd_curr_thread_handle; | 98 | __thread struct tracecmd_input *tracecmd_curr_thread_handle; |
@@ -2085,6 +2086,15 @@ int tracecmd_init_data(struct tracecmd_input *handle) | |||
2085 | handle->cpu_data[cpu].file_offset = offset; | 2086 | handle->cpu_data[cpu].file_offset = offset; |
2086 | handle->cpu_data[cpu].file_size = size; | 2087 | handle->cpu_data[cpu].file_size = size; |
2087 | 2088 | ||
2089 | if (offset + size > handle->total_file_size) { | ||
2090 | /* this happens if the file got truncated */ | ||
2091 | printf("File possibly truncated. " | ||
2092 | "Need at least %llu, but file size is %lu.\n", | ||
2093 | offset + size, handle->total_file_size); | ||
2094 | errno = EINVAL; | ||
2095 | return -1; | ||
2096 | } | ||
2097 | |||
2088 | if (init_cpu(handle, cpu)) | 2098 | if (init_cpu(handle, cpu)) |
2089 | return -1; | 2099 | return -1; |
2090 | } | 2100 | } |
@@ -2189,6 +2199,12 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd) | |||
2189 | handle->header_files_start = | 2199 | handle->header_files_start = |
2190 | lseek64(handle->fd, 0, SEEK_CUR); | 2200 | lseek64(handle->fd, 0, SEEK_CUR); |
2191 | 2201 | ||
2202 | handle->total_file_size = | ||
2203 | lseek64(handle->fd, 0, SEEK_END); | ||
2204 | |||
2205 | handle->header_files_start = | ||
2206 | lseek64(handle->fd, handle->header_files_start, SEEK_SET); | ||
2207 | |||
2192 | return handle; | 2208 | return handle; |
2193 | 2209 | ||
2194 | failed_read: | 2210 | failed_read: |