fprintf: Fix up decrementing recursivity level in type__fprintf()

In some exit paths we were accessing tconf before we had copied it from
conf, and we also were losing track of the original type that could have
been expanded and where we bumped the recursivity level member, so just
store that original type and if it is set, decrement its recursivity
level.

This addresses these coverity report entries:

  Error: UNINIT (CWE-457): [#def21]
  dwarves-1.13/dwarves_fprintf.c:600: var_decl: Declaring variable "tconf" without initializer.
  dwarves-1.13/dwarves_fprintf.c:774: uninit_use: Using uninitialized value "tconf.expand_types".
  #  772|   	}
  #  773|   out:
  #  774|-> 	if (tconf.expand_types)
  #  775|   		--type->recursivity_level;
  #  776|

  Error: FORWARD_NULL (CWE-476): [#def22]
  dwarves-1.13/dwarves_fprintf.c:605: var_compare_op: Comparing "type" to null implies that "type" might be null.
  dwarves-1.13/dwarves_fprintf.c:775: var_deref_op: Dereferencing null pointer "type".
  #  773|   out:
  #  774|   	if (tconf.expand_types)
  #  775|-> 		--type->recursivity_level;
  #  776|
  #  777|   	return printed;

Reported-by: William Cohen <wcohen@redhat.com>
Fixes: f84bf73d54 ("dwarves: Move the fprintf code to a new source file.")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-07-02 16:17:44 -03:00
parent 93c3cdf897
commit c6a9a0eb6a
1 changed files with 4 additions and 2 deletions

View File

@ -597,6 +597,7 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
char namebf[256];
char namebfptr[258];
struct type *ctype;
struct tag *type_expanded = NULL;
struct conf_fprintf tconf;
size_t printed = 0;
int expand_types = conf->expand_types;
@ -640,6 +641,7 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
if (type->recursivity_level != 0)
expand_types = 0;
++type->recursivity_level;
type_expanded = type;
}
if (expand_types) {
@ -779,8 +781,8 @@ print_default:
break;
}
out:
if (tconf.expand_types)
--type->recursivity_level;
if (type_expanded)
--type_expanded->recursivity_level;
return printed;
out_type_not_found: