btrfs-progs: string-table: check bounds before writing to a cell

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2022-11-28 19:57:43 +01:00
parent 9cae43183e
commit b397e0eb63

View File

@ -18,6 +18,7 @@
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "common/messages.h"
#include "common/string-table.h"
/*
@ -54,6 +55,12 @@ char *table_vprintf(struct string_table *tab, unsigned int column, unsigned int
if (!msg)
return NULL;
if (column >= tab->ncols || row >= tab->nrows) {
error("attempt to write outside of table: col %u row %u fmt %s",
column, row, fmt);
return NULL;
}
if (tab->cells[idx])
free(tab->cells[idx]);
tab->cells[idx] = msg;