Add a very small hack to make the UAT update callback error string freeable, and

convert all existing UAT update callbacks to use glib memory instead of
ephemeral memory for that string.

UAT code paths are entirely distinct from packet dissection, so using ephemeral
memory was the wrong choice, because there was no guarantees about when it would
be freed.

The move away from emem still needs to be propogated deeper into the UAT code
itself at some point.

Net effect: remove another bunch of emem calls from dissectors, where replacing
with wmem would have caused assertions.

svn path=/trunk/; revision=52854
This commit is contained in:
Evan Huus 2013-10-25 22:14:25 +00:00
parent 7a3febacac
commit 95f484a91e
22 changed files with 87 additions and 76 deletions

View File

@ -673,7 +673,7 @@ static const TOP_ELEMENT_CONTROL canonifyTable[] = {
{ FALSE, FALSE, 0x0, TRUE, NULL, NULL }
};
static void
static void
clear_canon(void)
{
const TOP_ELEMENT_CONTROL *t = canonifyTable;
@ -736,10 +736,10 @@ c1222_uat_data_update_cb(void* n, const char** err)
c1222_uat_data_t* new_rec = (c1222_uat_data_t *)n;
if (new_rec->keynum > 0xff) {
*err = "Invalid key number; must be less than 256";
*err = g_strdup("Invalid key number; must be less than 256");
}
if (new_rec->keylen != EAX_SIZEOF_KEY) {
*err = "Invalid key size; must be 16 bytes";
*err = g_strdup("Invalid key size; must be 16 bytes");
}
}

View File

@ -408,13 +408,13 @@ attribute_types_update_cb(void *r, const char **err)
char c;
if (rec->attribute_type == NULL) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Attribute type can't be empty");
*err = g_strdup("Attribute type can't be empty");
return;
}
g_strstrip(rec->attribute_type);
if (rec->attribute_type[0] == 0) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Attribute type can't be empty");
*err = g_strdup("Attribute type can't be empty");
return;
}
@ -423,7 +423,7 @@ attribute_types_update_cb(void *r, const char **err)
*/
c = proto_check_field_name(rec->attribute_type);
if (c) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Attribute type can't contain '%c'", c);
*err = g_strdup_printf("Attribute type can't contain '%c'", c);
return;
}

View File

@ -2230,7 +2230,7 @@ static void
snmp_users_update_cb(void* p _U_, const char** err)
{
snmp_ue_assoc_t* ue = (snmp_ue_assoc_t*)p;
emem_strbuf_t* es = ep_strbuf_new("");
GString* es = g_string_new("");
unsigned int i;
*err = NULL;
@ -2240,14 +2240,14 @@ snmp_users_update_cb(void* p _U_, const char** err)
return;
if (! ue->user.userName.len)
ep_strbuf_append_printf(es,"no userName\n");
g_string_append_printf(es,"no userName\n");
for (i=0; i<num_ueas-1; i++) {
snmp_ue_assoc_t* u = &(ueas[i]);
/* RFC 3411 section 5 */
if ((u->engine.len > 0) && (u->engine.len < 5 || u->engine.len > 32)) {
ep_strbuf_append_printf(es, "Invalid engineId length (%u). Must be between 5 and 32 (10 and 64 hex digits)\n", u->engine.len);
g_string_append_printf(es, "Invalid engineId length (%u). Must be between 5 and 32 (10 and 64 hex digits)\n", u->engine.len);
}
@ -2257,21 +2257,21 @@ snmp_users_update_cb(void* p _U_, const char** err)
if (u->engine.len > 0 && memcmp( u->engine.data, ue->engine.data, u->engine.len ) == 0) {
if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
/* XXX: make a string for the engineId */
ep_strbuf_append_printf(es,"Duplicate key (userName='%s')\n",ue->user.userName.data);
g_string_append_printf(es,"Duplicate key (userName='%s')\n",ue->user.userName.data);
}
}
if (u->engine.len == 0) {
if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
ep_strbuf_append_printf(es,"Duplicate key (userName='%s' engineId=NONE)\n",ue->user.userName.data);
g_string_append_printf(es,"Duplicate key (userName='%s' engineId=NONE)\n",ue->user.userName.data);
}
}
}
}
if (es->len) {
es = ep_strbuf_truncate(es,es->len-1);
*err = ep_strdup(es->str);
es = g_string_truncate(es,es->len-1);
*err = g_string_free(es, FALSE);
}
return;

View File

@ -408,7 +408,7 @@ static void macro_update(void* mp, const gchar** error) {
if (m == &(macros[i])) continue;
if ( g_str_equal(m->name,macros[i].name) ) {
*error = ep_strdup_printf("macro '%s' exists already", m->name);
*error = g_strdup_printf("macro '%s' exists already", m->name);
m->usable = FALSE;
return;
}

View File

@ -1212,7 +1212,7 @@ static void uat_bootp_record_update_cb(void* r, const char** err) {
uat_bootp_record_t* rec = (uat_bootp_record_t *)r;
if ((rec->opt == 0) || (rec->opt >=BOOTP_OPT_NUM-1))
*err = ep_strdup_printf("Option must be between 1 and %d", BOOTP_OPT_NUM-2);
*err = g_strdup_printf("Option must be between 1 and %d", BOOTP_OPT_NUM-2);
}
static void uat_bootp_record_free_cb(void*r) {
@ -5320,7 +5320,7 @@ bootp_init_protocol(void)
/* Now apply the custom options */
for (i = 0; i < num_bootp_records_uat; i++)
{
bootp_opt[uat_bootp_records[i].opt].text = se_strdup(uat_bootp_records[i].text);
bootp_opt[uat_bootp_records[i].opt].text = wmem_strdup(wmem_file_scope(), uat_bootp_records[i].text);
bootp_opt[uat_bootp_records[i].opt].ftype = uat_bootp_records[i].ftype;
bootp_opt[uat_bootp_records[i].opt].phf = NULL;
}

View File

@ -724,7 +724,7 @@ static const TOP_ELEMENT_CONTROL canonifyTable[] = {
{ FALSE, FALSE, 0x0, TRUE, NULL, NULL }
};
static void
static void
clear_canon(void)
{
const TOP_ELEMENT_CONTROL *t = canonifyTable;
@ -787,10 +787,10 @@ c1222_uat_data_update_cb(void* n, const char** err)
c1222_uat_data_t* new_rec = (c1222_uat_data_t *)n;
if (new_rec->keynum > 0xff) {
*err = "Invalid key number; must be less than 256";
*err = g_strdup("Invalid key number; must be less than 256");
}
if (new_rec->keylen != EAX_SIZEOF_KEY) {
*err = "Invalid key size; must be 16 bytes";
*err = g_strdup("Invalid key size; must be 16 bytes");
}
}

View File

@ -157,13 +157,13 @@ header_fields_update_cb(void *r, const char **err)
char c;
if (rec->header_name == NULL) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Header name can't be empty");
*err = g_strdup("Header name can't be empty");
return;
}
g_strstrip(rec->header_name);
if (rec->header_name[0] == 0) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Header name can't be empty");
*err = g_strdup("Header name can't be empty");
return;
}
@ -172,7 +172,7 @@ header_fields_update_cb(void *r, const char **err)
*/
c = proto_check_field_name(rec->header_name);
if (c) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Header name can't contain '%c'", c);
*err = g_strdup_printf("Header name can't contain '%c'", c);
return;
}

View File

@ -172,7 +172,7 @@ uat_wep_key_record_update_cb(void* r, const char** err)
decryption_key_t* dk;
if (rec->string == NULL) {
*err = ep_strdup_printf("Key can't be blank");
*err = g_strdup("Key can't be blank");
} else {
g_strstrip(rec->string);
dk = parse_key_string(rec->string, rec->key);
@ -183,25 +183,25 @@ uat_wep_key_record_update_cb(void* r, const char** err)
case AIRPDCAP_KEY_TYPE_WEP_40:
case AIRPDCAP_KEY_TYPE_WEP_104:
if (rec->key != AIRPDCAP_KEY_TYPE_WEP) {
*err = ep_strdup_printf("Invalid key format");
*err = g_strdup("Invalid key format");
}
break;
case AIRPDCAP_KEY_TYPE_WPA_PWD:
if (rec->key != AIRPDCAP_KEY_TYPE_WPA_PWD) {
*err = ep_strdup_printf("Invalid key format");
*err = g_strdup("Invalid key format");
}
break;
case AIRPDCAP_KEY_TYPE_WPA_PSK:
if (rec->key != AIRPDCAP_KEY_TYPE_WPA_PSK) {
*err = ep_strdup_printf("Invalid key format");
*err = g_strdup("Invalid key format");
}
break;
default:
*err = ep_strdup_printf("Invalid key format");
*err = g_strdup("Invalid key format");
break;
}
} else {
*err = ep_strdup_printf("Invalid key format");
*err = g_strdup("Invalid key format");
}
}
}

View File

@ -134,15 +134,18 @@ addr_uat_update_cb(void *r, const char **err)
static_addr_t *map = (static_addr_t *)r;
/* Ensure a valid short address */
if (map->addr16 >= IEEE802154_NO_ADDR16) {
*err = "Invalid short address";
*err = g_strdup("Invalid short address");
return;
}
/* Ensure a valid PAN identifier. */
if (map->pan >= IEEE802154_BCAST_PAN) {
*err = "Invalid PAN identifier";
*err = g_strdup("Invalid PAN identifier");
return;
}
/* Ensure a valid EUI-64 length */
if (map->eui64_len != sizeof(guint64)) {
*err = "Invalid EUI-64 length";
*err = g_strdup("Invalid EUI-64 length");
return;
}
} /* ieee802154_addr_uat_update_cb */

View File

@ -288,13 +288,13 @@ header_fields_update_cb(void *r, const char **err)
char c;
if (rec->header_name == NULL) {
*err = ep_strdup_printf("Header name can't be empty");
*err = g_strdup("Header name can't be empty");
return;
}
g_strstrip(rec->header_name);
if (rec->header_name[0] == 0) {
*err = ep_strdup_printf("Header name can't be empty");
*err = g_strdup("Header name can't be empty");
return;
}
@ -303,7 +303,7 @@ header_fields_update_cb(void *r, const char **err)
*/
c = proto_check_field_name(rec->header_name);
if (c) {
*err = ep_strdup_printf("Header name can't contain '%c'", c);
*err = g_strdup_printf("Header name can't contain '%c'", c);
return;
}

View File

@ -4965,17 +4965,17 @@ static void ikev1_uat_data_update_cb(void* p, const char** err) {
ikev1_uat_data_key_t *ud = (ikev1_uat_data_key_t *)p;
if (ud->icookie_len != COOKIE_SIZE) {
*err = ep_strdup_printf("Length of Initiator's COOKIE must be %d octets (%d hex characters).", COOKIE_SIZE, COOKIE_SIZE * 2);
*err = g_strdup_printf("Length of Initiator's COOKIE must be %d octets (%d hex characters).", COOKIE_SIZE, COOKIE_SIZE * 2);
return;
}
if (ud->key_len == 0) {
*err = ep_strdup_printf("Must have Encryption key.");
*err = g_strdup_printf("Must have Encryption key.");
return;
}
if (ud->key_len > MAX_KEY_SIZE) {
*err = ep_strdup_printf("Length of Encryption key limited to %d octets (%d hex characters).", MAX_KEY_SIZE, MAX_KEY_SIZE * 2);
*err = g_strdup_printf("Length of Encryption key limited to %d octets (%d hex characters).", MAX_KEY_SIZE, MAX_KEY_SIZE * 2);
return;
}
@ -4994,12 +4994,12 @@ static void ikev2_uat_data_update_cb(void* p, const char** err) {
ikev2_uat_data_t *ud = (ikev2_uat_data_t *)p;
if (ud->key.spii_len != COOKIE_SIZE) {
*err = ep_strdup_printf("Length of Initiator's SPI must be %d octets (%d hex characters).", COOKIE_SIZE, COOKIE_SIZE * 2);
*err = g_strdup_printf("Length of Initiator's SPI must be %d octets (%d hex characters).", COOKIE_SIZE, COOKIE_SIZE * 2);
return;
}
if (ud->key.spir_len != COOKIE_SIZE) {
*err = ep_strdup_printf("Length of Responder's SPI must be %d octets (%d hex characters).", COOKIE_SIZE, COOKIE_SIZE * 2);
*err = g_strdup_printf("Length of Responder's SPI must be %d octets (%d hex characters).", COOKIE_SIZE, COOKIE_SIZE * 2);
return;
}
@ -5012,25 +5012,25 @@ static void ikev2_uat_data_update_cb(void* p, const char** err) {
}
if (ud->sk_ei_len != ud->encr_spec->key_len) {
*err = ep_strdup_printf("Length of SK_ei (%u octets) does not match the key length (%u octets) of the selected encryption algorithm.",
*err = g_strdup_printf("Length of SK_ei (%u octets) does not match the key length (%u octets) of the selected encryption algorithm.",
ud->sk_ei_len, ud->encr_spec->key_len);
return;
}
if (ud->sk_er_len != ud->encr_spec->key_len) {
*err = ep_strdup_printf("Length of SK_er (%u octets) does not match the key length (%u octets) of the selected encryption algorithm.",
*err = g_strdup_printf("Length of SK_er (%u octets) does not match the key length (%u octets) of the selected encryption algorithm.",
ud->sk_er_len, ud->encr_spec->key_len);
return;
}
if (ud->sk_ai_len != ud->auth_spec->key_len) {
*err = ep_strdup_printf("Length of SK_ai (%u octets) does not match the key length (%u octets) of the selected integrity algorithm.",
*err = g_strdup_printf("Length of SK_ai (%u octets) does not match the key length (%u octets) of the selected integrity algorithm.",
ud->sk_ai_len, ud->auth_spec->key_len);
return;
}
if (ud->sk_ar_len != ud->auth_spec->key_len) {
*err = ep_strdup_printf("Length of SK_ar (%u octets) does not match the key length (%u octets) of the selected integrity algorithm.",
*err = g_strdup_printf("Length of SK_ar (%u octets) does not match the key length (%u octets) of the selected integrity algorithm.",
ud->sk_ar_len, ud->auth_spec->key_len);
return;
}

View File

@ -310,7 +310,7 @@ k12_update_cb(void* r, const char** err)
gchar** protos;
guint num_protos, i;
protos = ep_strsplit(h->protos,":",0);
protos = g_strsplit(h->protos,":",0);
for (num_protos = 0; protos[num_protos]; num_protos++)
g_strstrip(protos[num_protos]);
@ -321,11 +321,13 @@ k12_update_cb(void* r, const char** err)
for (i = 0; i < num_protos; i++) {
if ( ! (h->handles[i] = find_dissector(protos[i])) ) {
h->handles[i] = data_handle;
*err = ep_strdup_printf("Could not find dissector for: '%s'",protos[i]);
g_strfreev(protos);
*err = g_strdup_printf("Could not find dissector for: '%s'",protos[i]);
return;
}
}
g_strfreev(protos);
*err = NULL;
}

View File

@ -627,13 +627,13 @@ attribute_types_update_cb(void *r, const char **err)
char c;
if (rec->attribute_type == NULL) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Attribute type can't be empty");
*err = g_strdup("Attribute type can't be empty");
return;
}
g_strstrip(rec->attribute_type);
if (rec->attribute_type[0] == 0) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Attribute type can't be empty");
*err = g_strdup("Attribute type can't be empty");
return;
}
@ -642,7 +642,7 @@ attribute_types_update_cb(void *r, const char **err)
*/
c = proto_check_field_name(rec->attribute_type);
if (c) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Attribute type can't contain '%c'", c);
*err = g_strdup_printf("Attribute type can't contain '%c'", c);
return;
}

View File

@ -3404,12 +3404,12 @@ sccp_users_update_cb(void *r, const char **err)
empty = range_empty();
if (ranges_are_equal(u->called_pc, empty)) {
*err = ep_strdup_printf("Must specify a PC");
*err = g_strdup("Must specify a PC");
return;
}
if (ranges_are_equal(u->called_ssn, empty)) {
*err = ep_strdup_printf("Must specify an SSN");
*err = g_strdup("Must specify an SSN");
return;
}

View File

@ -3445,7 +3445,7 @@ static void
snmp_users_update_cb(void* p _U_, const char** err)
{
snmp_ue_assoc_t* ue = (snmp_ue_assoc_t*)p;
emem_strbuf_t* es = ep_strbuf_new("");
GString* es = g_string_new("");
unsigned int i;
*err = NULL;
@ -3455,14 +3455,14 @@ snmp_users_update_cb(void* p _U_, const char** err)
return;
if (! ue->user.userName.len)
ep_strbuf_append_printf(es,"no userName\n");
g_string_append_printf(es,"no userName\n");
for (i=0; i<num_ueas-1; i++) {
snmp_ue_assoc_t* u = &(ueas[i]);
/* RFC 3411 section 5 */
if ((u->engine.len > 0) && (u->engine.len < 5 || u->engine.len > 32)) {
ep_strbuf_append_printf(es, "Invalid engineId length (%u). Must be between 5 and 32 (10 and 64 hex digits)\n", u->engine.len);
g_string_append_printf(es, "Invalid engineId length (%u). Must be between 5 and 32 (10 and 64 hex digits)\n", u->engine.len);
}
@ -3472,21 +3472,21 @@ snmp_users_update_cb(void* p _U_, const char** err)
if (u->engine.len > 0 && memcmp( u->engine.data, ue->engine.data, u->engine.len ) == 0) {
if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
/* XXX: make a string for the engineId */
ep_strbuf_append_printf(es,"Duplicate key (userName='%s')\n",ue->user.userName.data);
g_string_append_printf(es,"Duplicate key (userName='%s')\n",ue->user.userName.data);
}
}
if (u->engine.len == 0) {
if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
ep_strbuf_append_printf(es,"Duplicate key (userName='%s' engineId=NONE)\n",ue->user.userName.data);
g_string_append_printf(es,"Duplicate key (userName='%s' engineId=NONE)\n",ue->user.userName.data);
}
}
}
}
if (es->len) {
es = ep_strbuf_truncate(es,es->len-1);
*err = ep_strdup(es->str);
es = g_string_truncate(es,es->len-1);
*err = g_string_free(es, FALSE);
}
return;

View File

@ -5249,14 +5249,6 @@ ssldecrypt_free_cb(void *r)
g_free(h->password);
}
static void
ssldecrypt_update_cb(void *r _U_, const char **err)
{
if (err)
*err = NULL;
return;
}
static void*
ssldecrypt_copy_cb(void *dest, const void *orig, size_t len _U_)
{
@ -6085,7 +6077,7 @@ proto_register_ssl(void)
UAT_AFFECTS_DISSECTION, /* affects dissection of packets, but not set of named fields */
NULL, /* Help section (currently a wiki page) */
ssldecrypt_copy_cb,
ssldecrypt_update_cb,
NULL,
ssldecrypt_free_cb,
ssl_parse_uat,
sslkeylist_uats_flds);

View File

@ -175,7 +175,7 @@ vcdu_uat_data_update_cb(void *p, const char **err) {
uat_channel_t *ud = (uat_channel_t *)p;
if (ud->channel >= 64) {
*err = wmem_strdup_printf(wmem_packet_scope(), "Channel must be between 0-63.");
*err = g_strdup("Channel must be between 0-63.");
return;
}
}

View File

@ -160,18 +160,18 @@ static void uat_key_record_update_cb(void* r, const char** err) {
uat_key_record_t* rec = (uat_key_record_t *)r;
if (rec->string == NULL) {
*err = ep_strdup_printf("Key can't be blank");
*err = g_strdup("Key can't be blank");
} else {
g_strstrip(rec->string);
if (rec->string[0] != 0) {
*err = NULL;
if ( !zbee_security_parse_key(rec->string, rec->key, rec->byte_order) ) {
*err = ep_strdup_printf("Expecting %d hexadecimal bytes or\n"
*err = g_strdup_printf("Expecting %d hexadecimal bytes or\n"
"a %d character double-quoted string", ZBEE_SEC_CONST_KEYSIZE, ZBEE_SEC_CONST_KEYSIZE);
}
} else {
*err = ep_strdup_printf("Key can't be blank");
*err = g_strdup("Key can't be blank");
}
}
}

View File

@ -195,7 +195,7 @@ static void geoip_db_post_update_cb(void) {
/**
* Initialize GeoIP lookups
*/
void
void
geoip_db_pref_init(module_t *nameres)
{
static uat_field_t geoip_db_paths_fields[] = {

View File

@ -81,7 +81,10 @@ static guint linenum;
static gchar *parse_str;
static guint parse_str_pos;
#define ERROR(fmtd) do { error = ep_strdup_printf("%s:%d: %s",uat->filename,linenum,ep_strdup_printf fmtd); yyterminate(); } while(0)
#define ERROR(fmtd) do { \
error = ep_strdup_printf("%s:%d: %s",uat->filename,linenum,ep_strdup_printf fmtd); \
yyterminate(); \
} while(0)
#define SET_FIELD() \
{ const gchar* errx; \
@ -237,7 +240,7 @@ comment #[^\n]*\n
<END_OF_RECORD>{newline} {
void* rec;
const gchar* err = NULL;
const char* err = NULL;
linenum++;
@ -251,7 +254,12 @@ comment #[^\n]*\n
uat->update_cb(rec,&err);
if (err) {
ERROR(("%s",err));
char *tmp = ep_strdup(err);
/* XXX bit of a hack to remove emem from dissectors, this can
* be removed as proper use of glib memory is propogated
* through the rest of the UAT code */
g_free((char*)err);
ERROR(("%s",tmp));
}
valid_record = TRUE;

View File

@ -73,7 +73,7 @@ uat_plen_record_update_cb(void *r, const char **err)
{
uat_plen_record_t *rec = (uat_plen_record_t*)r;
if (rec->packet_range->nranges < 1) {
*err = ep_strdup_printf("Invalid range string");
*err = g_strdup("Invalid range string");
return;
}

View File

@ -373,7 +373,13 @@ static gboolean uat_dlg_cb(GtkWidget *win _U_, gpointer user_data) {
dd->uat->update_cb(dd->rec, &err);
if (err) {
err = ep_strdup_printf("error updating record: %s", err);
char *tmp;
tmp = ep_strdup_printf("error updating record: %s", err);
/* XXX bit of a hack to remove emem from dissectors, this can
* be removed as proper use of glib memory is propogated
* through the rest of the UAT code */
g_free((char*)err);
err = tmp;
goto on_failure;
}
}