Skip to content

Commit

Permalink
fix 2ndheader logging null-deref
Browse files Browse the repository at this point in the history
Fixes fuzz GH LibreDWG#890
  • Loading branch information
rurban committed Dec 7, 2023
1 parent 76a574c commit 10c79fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,8 @@ secondheader_private (Bit_Chain *restrict dat, Dwg_Data *restrict dwg)
{
Bit_Chain *str_dat = dat;
Dwg_SecondHeader *_obj = &dwg->secondheader;
Dwg_Object *obj = NULL;
// for error logging only:
Dwg_Object *obj = &(Dwg_Object){ .name = (char*)"2NDHEADER" };
int error = 0;
BITCODE_BL vcount;
if (!dat->chain || !dat->size)
Expand Down
3 changes: 2 additions & 1 deletion src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,8 @@ encode_secondheader_private (Bit_Chain *restrict dat, Dwg_Data *restrict dwg)
{
Bit_Chain *str_dat = dat;
Dwg_SecondHeader *_obj = &dwg->secondheader;
Dwg_Object *obj = NULL;
// for error logging only:
Dwg_Object *obj = &(Dwg_Object){ .name = (char*)"2NDHEADER" };
int error = 0;
BITCODE_BL vcount;
if (!dat->chain || !dat->size)
Expand Down
4 changes: 2 additions & 2 deletions src/spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
# define VALUEOUTOFBOUNDS(field, maxvalue) \
if (_IN_RANGE (_obj->field, maxvalue) && _obj->field > maxvalue) \
{ \
LOG_ERROR ("Invalid %s." #field " %lu", obj->name, \
LOG_ERROR ("Invalid %s." #field " %lu", obj ? obj->name : "", \
(unsigned long)_obj->field); \
_obj->field = 0; \
return DWG_ERR_VALUEOUTOFBOUNDS; \
}
# define SUB_VALUEOUTOFBOUNDS(o, field, maxvalue) \
if (_IN_RANGE (_obj->o.field, maxvalue) && _obj->o.field > maxvalue) \
{ \
LOG_ERROR ("Invalid %s." #field " %lu", obj->name, \
LOG_ERROR ("Invalid %s." #field " %lu", obj ? obj->name : "", \
(unsigned long)_obj->o.field); \
_obj->o.field = 0; \
return DWG_ERR_VALUEOUTOFBOUNDS; \
Expand Down

0 comments on commit 10c79fd

Please sign in to comment.