From 5e0387a4b7e22049044863514f1dfd8ae8811c07 Mon Sep 17 00:00:00 2001
From: Bento Loewenstein <bento.ls@gmail.com>
Date: Wed, 15 Sep 2010 22:56:08 -0300
Subject: [PATCH] WPrefs crashes when parsing menu with invalid items.

After creating my own Debian menu-method to parse data from update-menu and
generate a nested parenthesis hierachy as WPrefs' menu editor likes, I was
bitten by a small bug that involved a buggy script written by some clueless
guy with to little sleep time to be writing code (me), some "goto" ugliness
and a function returning a NULL pointer. That was enough to crash WPrefs.

This patch addresses this in the way I found more elegant. It converts the
item into a regular "EXEC" with "invalid command" on data->param.exec.command

Now it doesn't crash when parsing menus with invalid entries and tells the
user that there's something wrong with that entry.
---
 WPrefs.app/Menu.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/WPrefs.app/Menu.c b/WPrefs.app/Menu.c
index dccb85b..4751c1e 100644
--- a/WPrefs.app/Menu.c
+++ b/WPrefs.app/Menu.c
@@ -1029,8 +1029,14 @@ static ItemData *parseCommand(WMPropList * item)
 		} else if (strcmp(command, "LEGAL_PANEL") == 0) {
 			cmd = 11;
 		} else {
+
 			wwarning(_("unknown command '%s' in menu"), command);
-			goto error;
+			command = wstrdup("EXEC");
+			data->type = ExecInfo;
+			data->param.exec.command = wstrdup("invalid command");
+
+			return data;
+
 		}
 
 		data->type = CommandInfo;
@@ -1043,11 +1049,6 @@ static ItemData *parseCommand(WMPropList * item)
 	}
 
 	return data;
-
- error:
-	wfree(data);
-
-	return NULL;
 }
 
 static void updateFrameTitle(_Panel * panel, char *title, InfoType type)
-- 
1.7.1

