dont allow empty compound key names

This commit is contained in:
Murphy 2023-12-15 23:16:47 -05:00
parent d6a757ce2a
commit afda43984e
No known key found for this signature in database
GPG key ID: 988032A5638EE799
3 changed files with 15 additions and 0 deletions

View file

@ -525,6 +525,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);
free(name);

View file

@ -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;

View file

@ -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;