workbook: fix buffer underflow in defined names

Closes #444
This commit is contained in:
John McNamara 2024-05-16 00:53:08 +01:00
parent 284b61ba0b
commit af0b03a8f0
2 changed files with 42 additions and 0 deletions

View file

@ -65,3 +65,28 @@ CTEST(workbook, write_defined_names_sorted) {
lxw_workbook_free(workbook);
}
/* Test invalid names formats. */
CTEST(workbook, write_defined_names_invalid) {
char* got;
char exp[] = "";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, NULL);
workbook_define_name(workbook, "", "=123");
workbook_define_name(workbook, "Foo", "");
workbook_define_name(workbook, "Sheet1!", "=123");
workbook_define_name(workbook, "!", "=123");
_write_defined_names(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}