libselinux: Fix file labels for regexes with metachars

File labels assigned using the lookup_best_match() function do not
assign the best match if its regex contains metacharacters.

For non-exact regex matches, lookup_best_match() finds the closest match
by tracking the length of the matching prefix. Prefix match is tracked via
the prefix_len variable. This was previously calculated and set in
the spec_hasMetaChars() function. Commit 3cb6078 removed the
prefix_len calculation, this commit restores it.

Signed-off-by: Jeff Vander Stoep <jeffv@google.com>
This commit is contained in:
Jeff Vander Stoep 2015-07-01 08:31:13 -07:00 committed by Stephen Smalley
parent 539b408cc2
commit 35a7c3e536

View file

@ -148,6 +148,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
end = c + len;
spec->hasMetaChars = 0;
spec->prefix_len = len;
/* Look at each character in the RE specification string for a
* meta character. Return when any meta character reached. */
@ -164,6 +165,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
case '(':
case '{':
spec->hasMetaChars = 1;
spec->prefix_len = c - spec->regex_str;
return;
case '\\': /* skip the next character */
c++;