From Didier Gautheron via bug 4419:

se_alloc and ep_alloc never return NULL and se_alloc0 already initialized
data with 0.

svn path=/trunk/; revision=31654
This commit is contained in:
Stig Bjørlykke 2010-01-25 11:47:39 +00:00
parent 17a01968d9
commit c198fc6546
14 changed files with 52 additions and 252 deletions

View File

@ -1197,9 +1197,6 @@ void attach_fp_info(packet_info *pinfo, gboolean received, const char *protocol_
/* Allocate struct */
p_fp_info = se_alloc0(sizeof(struct fp_info));
if (!p_fp_info) {
return;
}
/* Check that the number of outhdr values looks sensible */
if (((strcmp(protocol_name, "fpiur_r5") == 0) && (outhdr_values_found != 2)) ||
@ -1367,9 +1364,6 @@ static void attach_mac_lte_info(packet_info *pinfo)
/* Allocate & zero struct */
p_mac_lte_info = se_alloc0(sizeof(struct mac_lte_info));
if (p_mac_lte_info == NULL) {
return;
}
/* Populate the struct from outhdr values */
p_mac_lte_info->crcStatusValid = FALSE;
@ -1416,9 +1410,6 @@ static void attach_rlc_lte_info(packet_info *pinfo)
/* Allocate & zero struct */
p_rlc_lte_info = se_alloc0(sizeof(struct rlc_lte_info));
if (p_rlc_lte_info == NULL) {
return;
}
p_rlc_lte_info->rlcMode = outhdr_values[i++];
p_rlc_lte_info->direction = outhdr_values[i++];
@ -1448,9 +1439,6 @@ static void attach_pdcp_lte_info(packet_info *pinfo)
/* Allocate & zero struct */
p_pdcp_lte_info = se_alloc0(sizeof(struct pdcp_lte_info));
if (p_pdcp_lte_info == NULL) {
return;
}
p_pdcp_lte_info->no_header_pdu = outhdr_values[i++];
p_pdcp_lte_info->plane = outhdr_values[i++];
@ -1552,9 +1540,6 @@ static void check_for_oob_mac_lte_events(packet_info *pinfo, tvbuff_t *tvb, prot
/* Allocate & zero struct */
p_mac_lte_info = se_alloc0(sizeof(struct mac_lte_info));
if (p_mac_lte_info == NULL) {
return;
}
/* This indicates to MAC dissector that it has an oob event */
p_mac_lte_info->length = 0;

View File

@ -2718,11 +2718,8 @@ dissect_cip_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, packet_info
{
/* copy IOI for access by response packet */
preq_info->pIOI = se_alloc( ioilen*2);
if ( preq_info->pIOI )
{
preq_info->IOILen = ioilen;
tvb_memcpy(tvb, preq_info->pIOI, offset+2, ioilen*2);
}
preq_info->IOILen = ioilen;
tvb_memcpy(tvb, preq_info->pIOI, offset+2, ioilen*2);
}
}
@ -2765,15 +2762,12 @@ dissect_cip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if ( preq_info == NULL )
{
preq_info = se_alloc( sizeof( cip_req_info_t ) );
if ( preq_info )
{
preq_info->bService = 0;
preq_info->dissector = NULL;
preq_info->IOILen = 0;
preq_info->pIOI = NULL;
preq_info->pData = NULL;
enip_info->cip_info = preq_info;
}
preq_info->bService = 0;
preq_info->dissector = NULL;
preq_info->IOILen = 0;
preq_info->pIOI = NULL;
preq_info->pData = NULL;
enip_info->cip_info = preq_info;
}
dissect_cip_data( tree, tvb, 0, pinfo, enip_info->cip_info );
}

View File

@ -3693,13 +3693,9 @@ dcm_state_new(void)
{
/* Not much fun. Just create very simple root structure */
dcm_state_t *ds=NULL;
dcm_state_t *ds;
ds = (dcm_state_t *) se_alloc0(sizeof(dcm_state_t));
if (ds) {
ds->first_assoc=NULL;
ds->last_assoc=NULL;
}
return ds;
}
@ -3732,9 +3728,7 @@ dcm_state_get(packet_info *pinfo, gboolean create)
if (dcm_data == NULL && create) {
dcm_data = dcm_state_new();
if (dcm_data != NULL) {
conversation_add_proto_data(conv, proto_dcm, dcm_data);
}
conversation_add_proto_data(conv, proto_dcm, dcm_data);
/* Mark it as DICOM conversation. Needed for the heuristic mode,
to prevent stealing subsequent packets by other dissectors
@ -3754,25 +3748,17 @@ dcm_state_assoc_new(dcm_state_t *dcm_data, guint32 packet_no)
dcm_state_assoc_t *assoc;
assoc = (dcm_state_assoc_t *) se_alloc0(sizeof(dcm_state_assoc_t));
if (assoc) {
assoc->packet_no = packet_no; /* Identifier */
assoc->next = NULL;
assoc->prev = NULL;
assoc->packet_no = packet_no; /* Identifier */
assoc->first_pctx = NULL; /* List of Presentation context objects */
assoc->last_pctx = NULL;
/* add to the end of the list */
if (dcm_data->last_assoc) {
dcm_data->last_assoc->next = assoc;
assoc->prev = dcm_data->last_assoc;
}
else {
dcm_data->first_assoc = assoc;
}
dcm_data->last_assoc = assoc;
/* add to the end of the list */
if (dcm_data->last_assoc) {
dcm_data->last_assoc->next = assoc;
assoc->prev = dcm_data->last_assoc;
}
else {
dcm_data->first_assoc = assoc;
}
dcm_data->last_assoc = assoc;
return assoc;
}
@ -3816,32 +3802,18 @@ dcm_state_pctx_new(dcm_state_assoc_t *assoc, guint8 pctx_id)
dcm_state_pctx_t *pctx=NULL;
pctx = se_alloc0(sizeof(dcm_state_pctx_t));
if (pctx) {
pctx->id = pctx_id;
pctx->syntax = DCM_UNK;
pctx->next = NULL;
pctx->prev = NULL;
pctx->id = pctx_id;
pctx->abss_uid = NULL;
pctx->abss_desc = NULL;
pctx->xfer_uid = NULL;
pctx->xfer_desc = NULL;
pctx->syntax = DCM_UNK;
pctx->first_pdv = NULL; /* List of PDV objects */
pctx->last_pdv = NULL;
/* add to the end of the list list */
if (assoc->last_pctx) {
assoc->last_pctx->next = pctx;
pctx->prev = assoc->last_pctx;
}
else {
assoc->first_pctx = pctx;
}
assoc->last_pctx = pctx;
/* add to the end of the list list */
if (assoc->last_pctx) {
assoc->last_pctx->next = pctx;
pctx->prev = assoc->last_pctx;
}
else {
assoc->first_pctx = pctx;
}
assoc->last_pctx = pctx;
return pctx;
}
@ -3880,58 +3852,20 @@ dcm_state_pdv_new(dcm_state_pctx_t *pctx, guint32 packet_no, guint32 offset)
dcm_state_pdv_t *pdv = NULL;
pdv = (dcm_state_pdv_t *) se_alloc0(sizeof(dcm_state_pdv_t));
if (pdv != NULL) {
pdv->syntax = DCM_UNK;
pdv->is_last_fragment = TRUE; /* Continuation PDVs are more tricky */
pdv->packet_no = packet_no;
pdv->offset = offset;
pdv->prev = NULL;
pdv->next = NULL;
pdv->data = NULL;
pdv->data_len = 0;
pdv->pctx_id = 0;
pdv->syntax = DCM_UNK;
pdv->desc = NULL;
pdv->sop_class_uid = NULL;
pdv->sop_instance_uid = NULL;
pdv->is_storage = FALSE;
pdv->is_flagvalid = FALSE;
pdv->is_command = FALSE;
pdv->is_last_fragment = TRUE; /* Continuation PDVs are more tricky */
pdv->is_corrupt = FALSE;
pdv->packet_no = packet_no;
pdv->offset = offset;
pdv->status = NULL;
pdv->command = NULL;
pdv->comment = NULL;
pdv->is_warning = FALSE;
pdv->message_id = 0;
pdv->message_id_resp = 0;
pdv->no_remaining = 0;
pdv->no_completed = 0;
pdv->no_failed = 0;
pdv->no_warning = 0;
pdv->open_tag.is_header_fragmented = FALSE;
pdv->open_tag.is_value_fragmented = FALSE;
pdv->open_tag.desc = NULL;
pdv->open_tag.len_total = 0;
pdv->open_tag.len_remaining = 0;
/* add to the end of the list list */
if (pctx->last_pdv) {
pctx->last_pdv->next = pdv;
pdv->prev = pctx->last_pdv;
}
else {
pctx->first_pdv = pdv;
}
pctx->last_pdv = pdv;
/* add to the end of the list list */
if (pctx->last_pdv) {
pctx->last_pdv->next = pdv;
pdv->prev = pctx->last_pdv;
}
else {
pctx->first_pdv = pdv;
}
pctx->last_pdv = pdv;
return pdv;
}

View File

@ -549,9 +549,6 @@ get_http_conversation_data(packet_info *pinfo)
/* Setup the conversation structure itself */
conv_data = se_alloc0(sizeof(http_conv_t));
conv_data->request_method = NULL;
conv_data->request_uri = NULL;
conversation_add_proto_data(conversation, proto_http,
conv_data);
}

View File

@ -502,10 +502,7 @@ spx_hash_insert(conversation_t *conversation, guint32 spx_src, guint16 spx_seq)
key->spx_src = spx_src;
key->spx_seq = spx_seq;
value = se_alloc(sizeof(spx_hash_value));
value->spx_ack = 0;
value->spx_all = 0;
value->num = 0;
value = se_alloc0(sizeof(spx_hash_value));
g_hash_table_insert(spx_hash, key, value);

View File

@ -208,27 +208,10 @@ typedef struct mpa_state mpa_state_t;
static mpa_state_t *
init_mpa_state(void)
{
mpa_state_t *state= NULL;
guint i;
mpa_state_t *state;
state = (mpa_state_t *) se_alloc(sizeof(mpa_state_t));
if (state != NULL) {
state->full_operation = FALSE;
state->req_frame_num = 0;
state->rep_frame_num = 0;
state->ini_exp_m_res = FALSE;
state->res_exp_m_ini = FALSE;
for (i=0; i<2; i++) {
state->minfo[i].port = 0;
state->minfo[i].seq = 0;
state->minfo[i].valid = FALSE;
}
state->crc = FALSE;
state->revision = -1;
} else {
THROW(OutOfMemoryError);
}
state = (mpa_state_t *) se_alloc0(sizeof(mpa_state_t));
state->revision = -1;
return state;
}

View File

@ -701,9 +701,6 @@ static gboolean dissect_mac_lte_heur(tvbuff_t *tvb, packet_info *pinfo,
if (p_mac_lte_info == NULL) {
/* Allocate new info struct for this frame */
p_mac_lte_info = se_alloc0(sizeof(struct mac_lte_info));
if (p_mac_lte_info == NULL) {
return FALSE;
}
infoAlreadySet = FALSE;
}
else {
@ -1179,9 +1176,6 @@ static void call_rlc_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tr
/* Resuse or create RLC info */
p_rlc_lte_info = p_get_proto_data(pinfo->fd, proto_rlc_lte);
if (p_rlc_lte_info == NULL) {
p_rlc_lte_info = se_alloc0(sizeof(struct rlc_lte_info));
}
/* Fill in struct details for srb channels */
p_rlc_lte_info->rlcMode = mode;

View File

@ -204,12 +204,7 @@ void msrp_add_address( packet_info *pinfo,
*/
if (!p_conv_data) {
/* Create conversation data */
p_conv_data = se_alloc(sizeof(struct _msrp_conversation_info));
if (!p_conv_data)
{
return;
}
memset(p_conv_data, 0, sizeof(struct _msrp_conversation_info));
p_conv_data = se_alloc0(sizeof(struct _msrp_conversation_info));
conversation_add_proto_data(p_conv, proto_msrp, p_conv_data);
}
@ -250,10 +245,6 @@ void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
/* Save this conversation info into packet info */
p_conv_packet_data = se_alloc(sizeof(struct _msrp_conversation_info));
if (!p_conv_packet_data)
{
return;
}
memcpy(p_conv_packet_data, p_conv_data,
sizeof(struct _msrp_conversation_info));

View File

@ -1396,9 +1396,6 @@ static gboolean dissect_pdcp_lte_heur(tvbuff_t *tvb, packet_info *pinfo,
if (p_pdcp_lte_info == NULL) {
/* Allocate new info struct for this frame */
p_pdcp_lte_info = se_alloc0(sizeof(struct pdcp_lte_info));
if (p_pdcp_lte_info == NULL) {
return FALSE;
}
infoAlreadySet = FALSE;
}
else {

View File

@ -175,10 +175,7 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/*
* No - create one and attach it.
*/
data_val = se_alloc(sizeof(struct pop_data_val));
data_val->msg_request = FALSE;
data_val->msg_read_len = 0;
data_val->msg_tot_len = 0;
data_val = se_alloc0(sizeof(struct pop_data_val));
conversation_add_proto_data(conversation, proto_pop, data_val);
}

View File

@ -364,9 +364,6 @@ static void show_AM_PDU_in_tree(packet_info *pinfo, proto_tree *tree, tvbuff_t *
if (p_pdcp_lte_info == NULL) {
p_pdcp_lte_info = se_alloc0(sizeof(struct pdcp_lte_info));
}
if (p_pdcp_lte_info == NULL) {
return;
}
p_pdcp_lte_info->channelType = Channel_DCCH;
p_pdcp_lte_info->direction = rlc_info->direction;
@ -604,11 +601,6 @@ static void checkChannelSequenceInfo(packet_info *pinfo, tvbuff_t *tvb,
p_channel_key = se_alloc(sizeof(rlc_channel_hash_key));
p_channel_status = se_alloc0(sizeof(rlc_channel_status));
/* Just give up if allocations failed */
if (!p_channel_key || !p_channel_status) {
return;
}
/* Copy key contents */
memcpy(p_channel_key, &channel_key, sizeof(rlc_channel_hash_key));
@ -1201,9 +1193,6 @@ static gboolean dissect_rlc_lte_heur(tvbuff_t *tvb, packet_info *pinfo,
if (p_rlc_lte_info == NULL) {
/* Allocate new info struct for this frame */
p_rlc_lte_info = se_alloc0(sizeof(struct rlc_lte_info));
if (p_rlc_lte_info == NULL) {
return FALSE;
}
infoAlreadySet = FALSE;
}
else {

View File

@ -569,12 +569,7 @@ void srtcp_add_address( packet_info *pinfo,
*/
if ( ! p_conv_data ) {
/* Create conversation data */
p_conv_data = se_alloc(sizeof(struct _rtcp_conversation_info));
if (!p_conv_data)
{
return;
}
memset(p_conv_data, 0, sizeof(struct _rtcp_conversation_info));
p_conv_data = se_alloc0(sizeof(struct _rtcp_conversation_info));
conversation_add_proto_data(p_conv, proto_rtcp, p_conv_data);
}
@ -2199,10 +2194,6 @@ void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
/* Save this conversation info into packet info */
p_conv_packet_data = se_alloc(sizeof(struct _rtcp_conversation_info));
if (!p_conv_packet_data)
{
return;
}
memcpy(p_conv_packet_data, p_conv_data,
sizeof(struct _rtcp_conversation_info));
@ -2292,13 +2283,7 @@ static void remember_outgoing_sr(packet_info *pinfo, long lsr)
if (!p_conv_data)
{
/* Allocate memory for data */
p_conv_data = se_alloc(sizeof(struct _rtcp_conversation_info));
if (!p_conv_data)
{
/* Give up if couldn't allocate space for memory */
return;
}
memset(p_conv_data, 0, sizeof(struct _rtcp_conversation_info));
p_conv_data = se_alloc0(sizeof(struct _rtcp_conversation_info));
/* Add it to conversation. */
conversation_add_proto_data(p_conv, proto_rtcp, p_conv_data);
@ -2318,13 +2303,7 @@ static void remember_outgoing_sr(packet_info *pinfo, long lsr)
/* Will use/create packet info */
if (!p_packet_data)
{
p_packet_data = se_alloc(sizeof(struct _rtcp_conversation_info));
if (!p_packet_data)
{
/* Give up if allocation fails */
return;
}
memset(p_packet_data, 0, sizeof(struct _rtcp_conversation_info));
p_packet_data = se_alloc0(sizeof(struct _rtcp_conversation_info));
p_add_proto_data(pinfo->fd, proto_rtcp, p_packet_data);
}
@ -2393,14 +2372,7 @@ static void calculate_roundtrip_delay(tvbuff_t *tvb, packet_info *pinfo,
if (!p_packet_data)
{
/* Create packet info if it doesn't exist */
p_packet_data = se_alloc(sizeof(struct _rtcp_conversation_info));
if (!p_packet_data)
{
/* Give up if allocation fails */
return;
}
memset(p_packet_data, 0, sizeof(struct _rtcp_conversation_info));
p_packet_data = se_alloc0(sizeof(struct _rtcp_conversation_info));
/* Set as packet info */
p_add_proto_data(pinfo->fd, proto_rtcp, p_packet_data);

View File

@ -8248,23 +8248,7 @@ static void dissect_RTPS_DATA_BATCH(tvbuff_t *tvb,
sample_info_max = 1024; /* Max size of sampleInfo shown */
}
sample_info_flags = (guint16 *)ep_alloc(sizeof(guint16) * sample_info_max);
if (sample_info_flags == NULL) {
proto_tree_add_text(tree,
tvb,
offset,
2,
"out of memory allocating sample_info_flags");
return;
}
sample_info_length = (guint32 *)ep_alloc(sizeof(guint32) * sample_info_max);
if (sample_info_length == NULL) {
proto_tree_add_text(tree,
tvb,
offset,
2,
"out of memory allocating sample_info_length");
return;
}
/* Sample Info List: start decoding the sample info list until the offset
* is greater or equal than 'sampleListOffset' */

View File

@ -1895,15 +1895,7 @@ dissect_sip_common(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tr
}
/* Initialise stat info for passing to tap */
stat_info = ep_alloc(sizeof(sip_info_value_t));
stat_info->response_code = 0;
stat_info->request_method = NULL;
stat_info->reason_phrase = NULL;
stat_info->resend = 0;
stat_info->setup_time = 0;
stat_info->tap_call_id = NULL;
stat_info->tap_from_addr = NULL;
stat_info->tap_to_addr = NULL;
stat_info = ep_alloc0(sizeof(sip_info_value_t));
col_set_str(pinfo->cinfo, COL_PROTOCOL, "SIP");
@ -3412,12 +3404,6 @@ guint sip_is_packet_resend(packet_info *pinfo,
p_key = se_alloc(sizeof(sip_hash_key));
p_val = se_alloc(sizeof(sip_hash_value));
/* Just give up if allocations failed */
if (!p_key || !p_val)
{
return 0;
}
/* Fill in key and value details */
g_snprintf(p_key->call_id, MAX_CALL_ID_SIZE, "%s", call_id);
SE_COPY_ADDRESS(&(p_key->dest_address), &pinfo->net_dst);