projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: ctf.c fscanf missing integer length check
[babeltrace.git]
/
formats
/
ctf
/
ctf.c
diff --git
a/formats/ctf/ctf.c
b/formats/ctf/ctf.c
index 521d7ad0643f31fcc2a72d46ebd1414dc25e8bcc..5ddf2f78ddc6e73e85e1936f50dad57672635607 100644
(file)
--- a/
formats/ctf/ctf.c
+++ b/
formats/ctf/ctf.c
@@
-1201,9
+1201,9
@@
int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
- int whence), FILE *metadata_fp)
+ int whence), FILE *metadata_fp,
+ struct ctf_scanner *scanner)
{
{
- struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_stream;
FILE *fp;
char *buf = NULL;
struct ctf_file_stream *metadata_stream;
FILE *fp;
char *buf = NULL;
@@
-1250,7
+1250,7
@@
int ctf_open_trace_metadata_read(struct ctf_trace *td,
if (ret) {
/* Warn about empty metadata */
fprintf(stderr, "[warning] Empty metadata.\n");
if (ret) {
/* Warn about empty metadata */
fprintf(stderr, "[warning] Empty metadata.\n");
- goto end
_packet_read
;
+ goto end;
}
td->metadata_string = buf;
td->metadata_packetized = 1;
}
td->metadata_string = buf;
td->metadata_packetized = 1;
@@
-1261,22
+1261,16
@@
int ctf_open_trace_metadata_read(struct ctf_trace *td,
td->byte_order = BYTE_ORDER;
/* Check text-only metadata header and version */
td->byte_order = BYTE_ORDER;
/* Check text-only metadata header and version */
- nr_items = fscanf(fp, "/* CTF %
u.%
u", &major, &minor);
+ nr_items = fscanf(fp, "/* CTF %
10u.%10
u", &major, &minor);
if (nr_items < 2)
fprintf(stderr, "[warning] Ill-shapen or missing \"/* CTF x.y\" header for text-only metadata.\n");
if (check_version(major, minor) < 0) {
ret = -EINVAL;
if (nr_items < 2)
fprintf(stderr, "[warning] Ill-shapen or missing \"/* CTF x.y\" header for text-only metadata.\n");
if (check_version(major, minor) < 0) {
ret = -EINVAL;
- goto end
_packet_read
;
+ goto end;
}
rewind(fp);
}
}
rewind(fp);
}
- scanner = ctf_scanner_alloc();
- if (!scanner) {
- fprintf(stderr, "[error] Error allocating scanner\n");
- ret = -ENOMEM;
- goto end_scanner_alloc;
- }
ret = ctf_scanner_append_ast(scanner, fp);
if (ret) {
fprintf(stderr, "[error] Error creating AST\n");
ret = ctf_scanner_append_ast(scanner, fp);
if (ret) {
fprintf(stderr, "[error] Error creating AST\n");
@@
-1303,9
+1297,6
@@
int ctf_open_trace_metadata_read(struct ctf_trace *td,
goto end;
}
end:
goto end;
}
end:
- ctf_scanner_free(scanner);
-end_scanner_alloc:
-end_packet_read:
if (fp) {
closeret = fclose(fp);
if (closeret) {
if (fp) {
closeret = fclose(fp);
if (closeret) {
@@
-2045,6
+2036,7
@@
int ctf_open_trace_read(struct ctf_trace *td,
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
+ struct ctf_scanner *scanner;
int ret, closeret;
struct dirent *dirent;
struct dirent *diriter;
int ret, closeret;
struct dirent *dirent;
struct dirent *diriter;
@@
-2074,8
+2066,15
@@
int ctf_open_trace_read(struct ctf_trace *td,
/*
* Keep the metadata file separate.
*/
/*
* Keep the metadata file separate.
*/
-
- ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp);
+ scanner = ctf_scanner_alloc();
+ if (!scanner) {
+ fprintf(stderr, "[error] Error allocating scanner\n");
+ ret = -ENOMEM;
+ goto error_metadata;
+ }
+ ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp,
+ scanner);
+ ctf_scanner_free(scanner);
if (ret) {
fprintf(stderr, "[warning] Unable to open trace metadata for path \"%s\".\n", path);
goto error_metadata;
if (ret) {
fprintf(stderr, "[warning] Unable to open trace metadata for path \"%s\".\n", path);
goto error_metadata;
@@
-2285,8
+2284,16
@@
int ctf_open_mmap_trace_read(struct ctf_trace *td,
{
int ret;
struct bt_mmap_stream *mmap_info;
{
int ret;
struct bt_mmap_stream *mmap_info;
+ struct ctf_scanner *scanner;
- ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp);
+ scanner = ctf_scanner_alloc();
+ if (!scanner) {
+ fprintf(stderr, "[error] Error allocating scanner\n");
+ ret = -ENOMEM;
+ goto error_scanner_alloc;
+ }
+ ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp,
+ scanner);
if (ret) {
goto error;
}
if (ret) {
goto error;
}
@@
-2302,10
+2309,12
@@
int ctf_open_mmap_trace_read(struct ctf_trace *td,
goto error;
}
}
goto error;
}
}
-
+ ctf_scanner_free(scanner);
return 0;
error:
return 0;
error:
+ ctf_scanner_free(scanner);
+error_scanner_alloc:
return ret;
}
return ret;
}
This page took
0.027179 seconds
and
4
git commands to generate.