[1/2] gprofng: skip unrecognized input command

Message ID 20241127035308.3738491-1-vladimir.mezentsev@oracle.com
State New
Headers
Series [1/2] gprofng: skip unrecognized input command |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Vladimir Mezentsev Nov. 27, 2024, 3:53 a.m. UTC
  From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>

gprofng crashes when the GUI sends an invalid command.
Skip unrecognized commands and return an error status to the GUI.

gprofng/ChangeLog
2024-11-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* src/ipc.cc (ipc_doWork): Skip unrecognized commands.
	* src/ipcio.cc (writeError): New function.
	* src/ipcio.h: Add RESPONSE_STATUS_ERROR.
---
 gprofng/src/ipc.cc   |  6 ++++--
 gprofng/src/ipcio.cc | 10 ++++++++++
 gprofng/src/ipcio.h  |  5 ++++-
 3 files changed, 18 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gprofng/src/ipc.cc b/gprofng/src/ipc.cc
index 3e706dbc9d0..feda1f8eb08 100644
--- a/gprofng/src/ipc.cc
+++ b/gprofng/src/ipc.cc
@@ -2534,8 +2534,10 @@  ipc_doWork (void *arg)
     }
   else
     {
-      ipc_log ("Unrecognized input cmd \"%s\"; Aborting.\n", inp);
-      return 1;
+      char *s = dbe_sprintf ("Unrecognized request: \"%s\"", inp);
+      ipc_log ("%s\n", s);
+      writeError (s, req);
+      free (s);
     }
   ipc_log ("  processing IPC command %s complete\n", inp);
   free (inp);
diff --git a/gprofng/src/ipcio.cc b/gprofng/src/ipcio.cc
index 8ff16d5a8e2..c20a22f9b60 100644
--- a/gprofng/src/ipcio.cc
+++ b/gprofng/src/ipcio.cc
@@ -776,6 +776,16 @@  writeString (const char *s, IPCrequest* req)
 			   RESPONSE_TYPE_COMPLETE, RESPONSE_STATUS_SUCCESS, OUTS);
 }
 
+void
+writeError (const char *s, IPCrequest* req)
+{
+  IPCresponse *OUTS = responseBufferPool->getNewResponse (BUFFER_SIZE_LARGE);
+  OUTS->sendByte (L_STRING);
+  OUTS->sendSVal (s);
+  writeResponseWithHeader (req->getRequestID (), req->getChannelID (),
+			   RESPONSE_TYPE_COMPLETE, RESPONSE_STATUS_ERROR, OUTS);
+}
+
 void
 writeObject (DbeObj obj, IPCrequest* req)
 {
diff --git a/gprofng/src/ipcio.h b/gprofng/src/ipcio.h
index 23c35fc33dd..7cef74311b8 100644
--- a/gprofng/src/ipcio.h
+++ b/gprofng/src/ipcio.h
@@ -40,6 +40,7 @@  typedef char *String;
 #define RESPONSE_STATUS_SUCCESS     1
 #define RESPONSE_STATUS_FAILURE     2
 #define RESPONSE_STATUS_CANCELLED   3
+#define RESPONSE_STATUS_ERROR       4
 
 #define RESPONSE_TYPE_ACK           0
 #define RESPONSE_TYPE_PROGRESS      1
@@ -60,7 +61,8 @@  enum IPCrequestStatus
   IN_PROGRESS,
   COMPLETED,
   CANCELLED_DEFAULT,
-  CANCELLED_IMMEDIATE
+  CANCELLED_IMMEDIATE,
+  UNDEFINED_REGUEST
 };
 
 enum IPCTraceLevel
@@ -151,6 +153,7 @@  String readString (IPCrequest*);
 void readRequestHeader ();
 
 // write to the wire
+void writeError (const char *, IPCrequest*);
 void writeString (const char *, IPCrequest*);
 void writeBoolean (bool, IPCrequest*);
 void writeInt (int, IPCrequest*);