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

John Johansen john.johansen at canonical.com
Wed Mar 7 14:17:22 UTC 2012


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>
---
 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




More information about the AppArmor mailing list