[apparmor] [PATCH 03/11] Fix transition character reporting of dfa dumps

Steve Beattie steve at nxnw.org
Thu Mar 8 00:20:40 UTC 2012


On Wed, Mar 07, 2012 at 06:17:22AM -0800, John Johansen wrote:
> Make them report a hex value strings instead of the default C++
> \vvvvv
> 
> Make them consistent,
> - Dump to report the default transition and what isn't transitioned
>   on it.
> 
> 
> Signed-off-by: John Johansen <john.johansen at canonical.com>

Acked-By: Steve Beattie <sbeattie at ubuntu.com>

> ---
>  parser/libapparmor_re/hfa.cc |   46 ++++++++++++++++++++++++++++++++++-------
>  1 files changed, 38 insertions(+), 8 deletions(-)
> 
> diff --git a/parser/libapparmor_re/hfa.cc b/parser/libapparmor_re/hfa.cc
> index f6ad385..887b135 100644
> --- a/parser/libapparmor_re/hfa.cc
> +++ b/parser/libapparmor_re/hfa.cc
> @@ -646,12 +646,34 @@ void DFA::dump(ostream & os)
>  	os << "\n";
>  
>  	for (Partition::iterator i = states.begin(); i != states.end(); i++) {
> -		if ((*i)->otherwise != nonmatching)
> -			os << **i << " -> " << *(*i)->otherwise << "\n";
> +		Chars excluded;
> +
>  		for (StateTrans::iterator j = (*i)->trans.begin();
>  		     j != (*i)->trans.end(); j++) {
> -			os << **i << " -> " << *(j)->second << ":  "
> -			   << j->first << "\n";
> +			if (j->second == nonmatching) {
> +				excluded.insert(j->first);
> +			} else {
> +				os << **i << " -> " << *(j)->second << ": 0x"
> +				   << hex << (int) j->first;
> +				if (isprint(j->first))
> +					os << " " << j->first;
> +				os << "\n";
> +			}
> +		}
> +
> +		if ((*i)->otherwise != nonmatching) {
> +			os << **i << " -> " << *(*i)->otherwise << ": [";
> +			if (!excluded.empty()) {
> +				os << "^";
> +				for (Chars::iterator k = excluded.begin();
> +				     k != excluded.end(); k++) {
> +					if (isprint(*k))
> +						os << *k;
> +					else
> +						os << "\\0x" << hex << (int) *k;
> +				}
> +			}
> +			os << "]\n";
>  		}
>  	}
>  	os << "\n";
> @@ -690,18 +712,26 @@ void DFA::dump_dot_graph(ostream & os)
>  			else {
>  				os << "\t\"" << **i << "\" -> \"" << *j->second
>  				   << "\" [" << "\n";
> -				os << "\t\tlabel=\"" << j->first << "\"\n";
> -				os << "\t]" << "\n";
> +				os << "\t\tlabel=\"";
> +				if (isprint(j->first))
> +					os << j->first;
> +				else
> +					os << "\\0xhex" << (int) j->first;
> +
> +				os << "\"\n\t]" << "\n";
>  			}
>  		}
>  		if ((*i)->otherwise != nonmatching) {
> -		  os << "\t\"" << **i << "\" -> \"" << *(*i)->otherwise
> +			os << "\t\"" << **i << "\" -> \"" << *(*i)->otherwise
>  			   << "\" [" << "\n";
>  			if (!excluded.empty()) {
>  				os << "\t\tlabel=\"[^";
>  				for (Chars::iterator i = excluded.begin();
>  				     i != excluded.end(); i++) {
> -					os << *i;
> +					if (isprint(*i))
> +						os << *i;
> +					else
> +						os << "\\0x" << hex << (int) *i;
>  				}
>  				os << "]\"" << "\n";
>  			}
> -- 
> 1.7.9
> 
> 
> -- 
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20120307/59c45212/attachment.pgp>


More information about the AppArmor mailing list