Skip to content

Commit

Permalink
dcerpc: fix error handling for alloc errors
Browse files Browse the repository at this point in the history
Fix error handling of stub parsers. In case of SCRealloc error the
function would return a non-error code. This could possibly lead to
memory corruption.

Reported-By: The Yahoo pentest team
  • Loading branch information
victorjulien committed Feb 25, 2015
1 parent ff0b6b5 commit 56196ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/app-layer-dcerpc-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ enum {
DCERPC_FIELD_MAX,
};

/** \internal
* \retval stub_len or 0 in case of error */
static uint32_t FragmentDataParser(Flow *f, void *dcerpcudp_state,
AppLayerParserState *pstate,
uint8_t *input, uint32_t input_len)
Expand Down Expand Up @@ -88,7 +90,7 @@ static uint32_t FragmentDataParser(Flow *f, void *dcerpcudp_state,
SCFree(*stub_data_buffer);
*stub_data_buffer = NULL;
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
goto end;
SCReturnUInt(0);
}

*stub_data_buffer = ptmp;
Expand All @@ -110,7 +112,6 @@ static uint32_t FragmentDataParser(Flow *f, void *dcerpcudp_state,
}
#endif

end:
SCReturnUInt((uint32_t)stub_len);
}

Expand Down
8 changes: 5 additions & 3 deletions src/app-layer-dcerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,10 @@ static uint32_t DCERPCParseREQUEST(DCERPC *dcerpc, uint8_t *input, uint32_t inpu
SCReturnUInt((uint32_t)(p - input));
}

static uint32_t StubDataParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_len) {
/** \internal
* \retval stub_len or 0 in case of error */
static uint32_t StubDataParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_len)
{
SCEnter();
uint8_t **stub_data_buffer = NULL;
uint32_t *stub_data_buffer_len = NULL;
Expand Down Expand Up @@ -1237,7 +1240,7 @@ static uint32_t StubDataParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_le
SCFree(*stub_data_buffer);
*stub_data_buffer = NULL;
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
goto end;
SCReturnUInt(0);
}
*stub_data_buffer = ptmp;

Expand All @@ -1261,7 +1264,6 @@ static uint32_t StubDataParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_le
}
#endif

end:
SCReturnUInt((uint32_t)stub_len);
}

Expand Down

0 comments on commit 56196ac

Please sign in to comment.