[PATCH] Handle empty event name spec gracefully for PPC

William Cohen <[email protected]>
Newsgroups gmane.linux.oprofile
Message-ID <[email protected]>
During testing Michael Petlan found that the giving an empty event
name in the event spec to operf on PPC machines would cause operf
crash.  Running the following following command would demonstrate
this problem:

  operf -e : /bin/ls

The problem was traced to event_name in _handle_powerpc_event_spec
function having a length of 0.  The strncmp using event_name in
_handle_powerpc_event_spec would indicate a match and cause strncpy to
be called to copy zero bytes. The zero length strncpy would crash
operf.  Added a check to make ensure that the string is non-zero
length.

Signed-off-by: William Cohen <[email protected]>
---
 libpe_utils/op_pe_utils.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libpe_utils/op_pe_utils.cpp b/libpe_utils/op_pe_utils.cpp
index f9638c77..2cae7840 100644
--- a/libpe_utils/op_pe_utils.cpp
+++ b/libpe_utils/op_pe_utils.cpp
@@ -588,7 +588,7 @@ static string _handle_powerpc_event_spec(string event_spec)
 		}
 		if (line[0] == ' ' || line[0] == '\t')
 			continue;
-		if (!strncmp(line, event_name, evt_name_len)) {
+		if (evt_name_len && !strncmp(line, event_name, evt_name_len)) {
 			// Found a potential match.  Check if it's a perfect match.
 			string save_event_name = event_name;
 			size_t full_evt_len = index(line, ':') - line;
-- 
2.17.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.