Skip to content

Commit

Permalink
libsepol/sepol_compute_sid: Do not destroy uninitialized context
Browse files Browse the repository at this point in the history
Avoid context_destroy() on "newcontext" before context_init() is called.

Fixes:
  libsepol-3.6/src/services.c:1335: var_decl: Declaring variable "newcontext" without initializer.
  libsepol-3.6/src/services.c:1462: uninit_use_in_call: Using uninitialized value "newcontext.range.level[0].cat.node" when calling "context_destroy".
  \# 1460|   	rc = sepol_sidtab_context_to_sid(sidtab, &newcontext, out_sid);
  \# 1461|         out:
  \# 1462|-> 	context_destroy(&newcontext);
  \# 1463|   	return rc;
  \# 1464|   }

Signed-off-by: Vit Mojzis <[email protected]>
Reviewed-by: Christian Göttsche <[email protected]>
Acked-by: Stephen Smalley <[email protected]>
  • Loading branch information
vmojzis authored and stephensmalley committed Jul 30, 2024
1 parent 017d7d5 commit 1f080ff
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions libsepol/src/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,14 +1362,12 @@ static int sepol_compute_sid(sepol_security_id_t ssid,
scontext = sepol_sidtab_search(sidtab, ssid);
if (!scontext) {
ERR(NULL, "unrecognized SID %d", ssid);
rc = -EINVAL;
goto out;
return -EINVAL;
}
tcontext = sepol_sidtab_search(sidtab, tsid);
if (!tcontext) {
ERR(NULL, "unrecognized SID %d", tsid);
rc = -EINVAL;
goto out;
return -EINVAL;
}

if (tclass && tclass <= policydb->p_classes.nprim)
Expand Down

0 comments on commit 1f080ff

Please sign in to comment.