Skip to content

Commit 10c79fd

Browse files
committed
fix 2ndheader logging null-deref
Fixes fuzz GH LibreDWG#890
1 parent 76a574c commit 10c79fd

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/decode.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,8 @@ secondheader_private (Bit_Chain *restrict dat, Dwg_Data *restrict dwg)
26112611
{
26122612
Bit_Chain *str_dat = dat;
26132613
Dwg_SecondHeader *_obj = &dwg->secondheader;
2614-
Dwg_Object *obj = NULL;
2614+
// for error logging only:
2615+
Dwg_Object *obj = &(Dwg_Object){ .name = (char*)"2NDHEADER" };
26152616
int error = 0;
26162617
BITCODE_BL vcount;
26172618
if (!dat->chain || !dat->size)

src/encode.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,8 @@ encode_secondheader_private (Bit_Chain *restrict dat, Dwg_Data *restrict dwg)
23532353
{
23542354
Bit_Chain *str_dat = dat;
23552355
Dwg_SecondHeader *_obj = &dwg->secondheader;
2356-
Dwg_Object *obj = NULL;
2356+
// for error logging only:
2357+
Dwg_Object *obj = &(Dwg_Object){ .name = (char*)"2NDHEADER" };
23572358
int error = 0;
23582359
BITCODE_BL vcount;
23592360
if (!dat->chain || !dat->size)

src/spec.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@
7676
# define VALUEOUTOFBOUNDS(field, maxvalue) \
7777
if (_IN_RANGE (_obj->field, maxvalue) && _obj->field > maxvalue) \
7878
{ \
79-
LOG_ERROR ("Invalid %s." #field " %lu", obj->name, \
79+
LOG_ERROR ("Invalid %s." #field " %lu", obj ? obj->name : "", \
8080
(unsigned long)_obj->field); \
8181
_obj->field = 0; \
8282
return DWG_ERR_VALUEOUTOFBOUNDS; \
8383
}
8484
# define SUB_VALUEOUTOFBOUNDS(o, field, maxvalue) \
8585
if (_IN_RANGE (_obj->o.field, maxvalue) && _obj->o.field > maxvalue) \
8686
{ \
87-
LOG_ERROR ("Invalid %s." #field " %lu", obj->name, \
87+
LOG_ERROR ("Invalid %s." #field " %lu", obj ? obj->name : "", \
8888
(unsigned long)_obj->o.field); \
8989
_obj->o.field = 0; \
9090
return DWG_ERR_VALUEOUTOFBOUNDS; \

0 commit comments

Comments
 (0)