From 9323dd869dfe481d46512c7f9b1a30d0b7d2d7c4 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Tue, 17 Sep 2019 06:57:00 +0100 Subject: libctf: make ctf_dump not crash on OOM ctf_dump calls ctf_str_append extensively but never checks to see if it returns NULL (on OOM). If it ever does, we truncate the string we are appending to and leak it! Instead, create a variant of ctf_str_append that returns the *original string* on OOM, and use it in ctf-dump. It is far better to omit a tiny piece of a dump on OOM than to omit a bigger piece, and it is also better to do this in what is after all purely debugging code than it is to uglify ctf-dump.c with huge numbers of checks for the out-of-memory case. Slightly truncated debugging output is better than no debugging output at all and an out-of-memory message. New in v4. libctf/ * ctf-impl.h (ctf_str_append_noerr): Declare. * ctf-util.c (ctf_str_append_noerr): Define in terms of ctf_str_append. * ctf-dump.c (str_append): New, call it. (ctf_dump_format_type): Use str_append, not ctf_str_append. (ctf_dump_label): Likewise. (ctf_dump_objts): Likewise. (ctf_dump_funcs): Likewise. (ctf_dump_var): Likewise. (ctf_dump_member): Likewise. (ctf_dump_type): Likewise. (ctf_dump): Likewise. --- libctf/ctf-impl.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libctf/ctf-impl.h') diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index bed34876..6040457 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -457,6 +457,7 @@ extern ssize_t ctf_pread (int fd, void *buf, ssize_t count, off_t offset); extern void *ctf_realloc (ctf_file_t *, void *, size_t); extern char *ctf_str_append (char *, const char *); +extern char *ctf_str_append_noerr (char *, const char *); extern const char *ctf_strerror (int); extern ctf_id_t ctf_type_resolve_unsliced (ctf_file_t *, ctf_id_t); -- cgit v1.1