/* read and check header, set stream id (and check) */
if (td->packet_header) {
/* Read packet header */
- generic_rw(&pos->parent, &td->packet_header->p);
-
+ ret = generic_rw(&pos->parent, &td->packet_header->p);
+ if (ret)
+ return ret;
len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("magic"));
if (len_index >= 0) {
struct definition_integer *defint;
if (stream->packet_context) {
/* Read packet context */
- generic_rw(&pos->parent, &stream->packet_context->p);
-
+ ret = generic_rw(&pos->parent, &stream->packet_context->p);
+ if (ret)
+ return ret;
/* read content size from header */
len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
if (len_index >= 0) {
/* Use content size if non-zero, else file size */
packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT;
}
+
+ /* Validate content size and packet size values */
+ if (packet_index.content_size > packet_index.packet_size) {
+ fprintf(stdout, "[error] Content size (%zu bits) is larger than packet size (%zu bits).\n",
+ packet_index.content_size, packet_index.packet_size);
+ return -EINVAL;
+ }
+
+ if (packet_index.packet_size > filestats.st_size * CHAR_BIT) {
+ fprintf(stdout, "[error] Packet size (%zu bits) is larger than file size (%zu bits).\n",
+ packet_index.content_size, filestats.st_size * CHAR_BIT);
+ return -EINVAL;
+ }
+
/* Save position after header and context */
packet_index.data_offset = pos->offset;
return ret;
}
-static
-int ctf_open_trace_write(struct ctf_trace *td, const char *path, int flags)
-{
- int ret;
-
- ret = mkdir(path, S_IRWXU|S_IRWXG);
- if (ret)
- return ret;
-
- /* Open trace directory */
- td->dir = opendir(path);
- if (!td->dir) {
- fprintf(stdout, "[error] Unable to open trace directory.\n");
- ret = -ENOENT;
- goto error;
- }
-
-
- return 0;
-
-error:
- return ret;
-}
-
struct trace_descriptor *ctf_open_trace(const char *path, int flags)
{
struct ctf_trace *td;
switch (flags & O_ACCMODE) {
case O_RDONLY:
+ if (!path) {
+ fprintf(stdout, "[error] Path missing for input CTF trace.\n");
+ goto error;
+ }
ret = ctf_open_trace_read(td, path, flags);
if (ret)
goto error;
case O_WRONLY:
fprintf(stdout, "[error] Opening CTF traces for output is not supported yet.\n");
goto error;
-#if 0
- ret = ctf_open_trace_write(td, path, flags);
- if (ret)
- goto error;
-#endif //0
- break;
default:
fprintf(stdout, "[error] Incorrect open flags.\n");
goto error;