From afda43984e84b6cf04bc72d5fea6551e5bd83c29 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Fri, 15 Dec 2023 23:16:47 -0500 Subject: [PATCH] dont allow empty compound key names --- src/json/read.c | 6 ++++++ src/main.c | 4 ++++ src/nbt/read.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/json/read.c b/src/json/read.c index 9b75597..b95bc13 100644 --- a/src/json/read.c +++ b/src/json/read.c @@ -524,6 +524,12 @@ static bool json_read_compound(tagdata_t *data, const stream_t *stream) { char *name = next.data.string.data; int name_len = next.data.string.len; + + if (name_len < 1) { + free(tags); + free(name); + return false; + } if (json_next_token(&next, stream) == false || next.type != TOK_COLON) { free(tags); diff --git a/src/main.c b/src/main.c index f4419eb..d49e5b6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include "lib.h" +#include "stream.h" #include "tag.h" #include "flags.h" @@ -42,12 +43,15 @@ int main(int argc, char **argv) { tag_t tag; if (tag_read(&tag, &flags.in, flags.fin) == false) error_and_die("error: failed to read tag\n"); + stream_close(&flags.in); if (tag.type != TAG_COMPOUND) error_and_die("error: nbt tag not a valid compound tag\n"); if (tag_print(&tag, &flags.out, flags.fout) == false) error_and_die("error: failed to write tag\n"); + stream_close(&flags.out); + tag_free(&tag); return 0; diff --git a/src/nbt/read.c b/src/nbt/read.c index d5dd827..cef04ca 100644 --- a/src/nbt/read.c +++ b/src/nbt/read.c @@ -131,6 +131,11 @@ static bool nbt_read_compound(tagdata_t *data, const stream_t *stream) { return false; } + if (tag.name_len < 1) { + free(tags); + return false; + } + if (tag.type == TAG_END) break;