aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-05-25 00:28:45 +0200
committerMichael Mann <mmann78@netscape.net>2017-05-26 17:31:01 +0000
commitc9b0e9c81335e098cdb256b1c58597cda96703b1 (patch)
treef0e2f87b53b2b9e45e90fb4c5195f008beb7e1dc /epan
parent940165933fea699b7592ea2b5f128bac27b443b5 (diff)
Report syntax errors in UAT prefs parsing
Add the cause for a syntax error while parsing UATs. Example output: $ tshark -ouat:ssl_keys:, tshark: Invalid -o flag "uat:ssl_keys:,": ssl_keys:1: No IP address given. $ tshark -ouat:unknown:, tshark: Invalid -o flag "uat:unknown:,": Unknown preference Change-Id: I549406c4e31a81d29f487ef47bdb3c22da084947 Reviewed-on: https://code.wireshark.org/review/21748 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Jakub Zawadzki <darkjames-ws@darkjames.pl> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r--epan/prefs.c13
-rw-r--r--epan/prefs.h21
2 files changed, 19 insertions, 15 deletions
diff --git a/epan/prefs.c b/epan/prefs.c
index 18fdc15c31..35ff3fa2a2 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -4510,10 +4510,9 @@ read_prefs_file(const char *pf_path, FILE *pf,
* a valid uat entry.
*/
static gboolean
-prefs_set_uat_pref(char *uat_entry) {
+prefs_set_uat_pref(char *uat_entry, char **errmsg) {
gchar *p, *colonp;
uat_t *uat;
- gchar *err = NULL;
gboolean ret;
colonp = strchr(uat_entry, ':');
@@ -4543,11 +4542,11 @@ prefs_set_uat_pref(char *uat_entry) {
uat = uat_find(uat_entry);
*colonp = ':';
if (uat == NULL) {
+ *errmsg = g_strdup("Unknown preference");
return FALSE;
}
- ret = uat_load_str(uat, p, &err);
- g_free(err);
+ ret = uat_load_str(uat, p, errmsg);
return ret;
}
@@ -4558,7 +4557,7 @@ prefs_set_uat_pref(char *uat_entry) {
* in some fashion.
*/
prefs_set_pref_e
-prefs_set_pref(char *prefarg)
+prefs_set_pref(char *prefarg, char **errmsg)
{
gchar *p, *colonp;
prefs_set_pref_e ret;
@@ -4573,6 +4572,8 @@ prefs_set_pref(char *prefarg)
mgcp_tcp_port_count = -1;
mgcp_udp_port_count = -1;
+ *errmsg = NULL;
+
colonp = strchr(prefarg, ':');
if (colonp == NULL)
return PREFS_SET_SYNTAX_ERR;
@@ -4599,7 +4600,7 @@ prefs_set_pref(char *prefarg)
if (strcmp(prefarg, "uat")) {
ret = set_pref(prefarg, p, NULL, TRUE);
} else {
- ret = prefs_set_uat_pref(p) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
+ ret = prefs_set_uat_pref(p, errmsg) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
}
*colonp = ':'; /* put the colon back */
return ret;
diff --git a/epan/prefs.h b/epan/prefs.h
index 85d66b6cf6..e757a25533 100644
--- a/epan/prefs.h
+++ b/epan/prefs.h
@@ -575,14 +575,8 @@ extern e_prefs *read_prefs(void);
into "*pf_path_return", and return the errno. */
WS_DLL_PUBLIC int write_prefs(char **);
-/*
- * Given a string of the form "<pref name>:<pref value>", as might appear
- * as an argument to a "-o" option, parse it and set the preference in
- * question. Return an indication of whether it succeeded or failed
- * in some fashion.
- *
- * XXX - should supply, for syntax errors, a detailed explanation of
- * the syntax error.
+/**
+ * Result of setting a preference.
*/
typedef enum {
PREFS_SET_OK, /* succeeded */
@@ -591,7 +585,16 @@ typedef enum {
PREFS_SET_OBSOLETE /* preference used to exist but no longer does */
} prefs_set_pref_e;
-WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg);
+/*
+ * Given a string of the form "<pref name>:<pref value>", as might appear
+ * as an argument to a "-o" option, parse it and set the preference in
+ * question. Return an indication of whether it succeeded or failed
+ * in some fashion.
+ *
+ * For syntax errors (return value PREFS_SET_SYNTAX_ERR), details (when
+ * available) are written into "errmsg" which must be freed with g_free.
+ */
+WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
/*
* Get or set a preference's obsolete status. These can be used to make a