Skip to content

Commit

Permalink
[mms_codec] Ignore broken part headers
Browse files Browse the repository at this point in the history
Since we know the total size of the part headers, a failure to parse them
doesn't stop us from parsing the rest of the PDU.

Broken part headers do occur in real life. One such example has been added
as a test case.
  • Loading branch information
monich committed May 15, 2014
1 parent 7ecde6f commit 1787cca
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
1 change: 1 addition & 0 deletions mms-lib/include/mms_lib_log.h
Expand Up @@ -22,6 +22,7 @@
log(mms_handler_log)\
log(mms_message_log)\
log(mms_attachment_log)\
log(mms_codec_log)\
log(mms_task_log)\
log(mms_task_http_log)\
log(mms_task_decode_log)\
Expand Down
14 changes: 12 additions & 2 deletions mms-lib/src/mms_codec.c
Expand Up @@ -43,6 +43,11 @@
#include "wsputil.h"
#include "mms_codec.h"

/* Logging */
#define MMS_LOG_MODULE_NAME mms_codec_log
#include "mms_lib_log.h"
MMS_LOG_MODULE_DEFINE("mms-codec");

#define MAX_ENC_VALUE_BYTES 6

#ifdef TEMP_FAILURE_RETRY
Expand Down Expand Up @@ -1295,8 +1300,13 @@ static gboolean mms_parse_attachments(struct wsp_header_iter *iter,
return FALSE;

if (attachment_parse_headers(&hi, part) == FALSE) {
free_attachment(part, NULL);
return FALSE;

/*
* Better to ignore this. It doesn't stop us from
* parsing the rest of the PDU. And yes, it does
* happen in real life.
*/
MMS_WARN("Failed to parse part headers");
}

if (wsp_header_iter_at_end(&hi) == FALSE) {
Expand Down
Binary file added mms-lib/test/mms_codec/data/m-retrieve_9.conf
Binary file not shown.
57 changes: 42 additions & 15 deletions mms-lib/test/mms_codec/test_mms_codec.c
Expand Up @@ -12,7 +12,8 @@
*
*/

#include "mms_log.h"
#include "mms_lib_util.h"
#include "mms_lib_log.h"
#include "mms_codec.h"

#define DATA_DIR "data/"
Expand Down Expand Up @@ -50,7 +51,6 @@ test_file(

int main(int argc, char* argv[])
{
int i, ret = RET_OK;
static const char* default_files[] = {
"m-acknowledge.ind",
"m-notification_1.ind",
Expand All @@ -66,30 +66,57 @@ int main(int argc, char* argv[])
"m-retrieve_6.conf",
"m-retrieve_7.conf",
"m-retrieve_8.conf",
"m-retrieve_9.conf",
"m-notifyresp.ind",
"m-read-rec.ind",
"m-send_1.req",
"m-send_2.req",
"m-send_3.req",
"m-send.conf"
};
mms_log_set_type(MMS_LOG_TYPE_STDOUT, "test_mms_codec");
mms_log_stdout_timestamp = FALSE;
mms_log_default.level = MMS_LOGLEVEL_INFO;
if (argc > 1) {
for (i=1; i<argc; i++) {
if (!test_file(argv[i])) {
ret = RET_ERR;
}

int ret = RET_ERR;
gboolean verbose = FALSE;
GOptionContext* options;
GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
{ NULL }
};

mms_lib_init(argv[0]);
options = g_option_context_new("[TESTS...] - MMS codec test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, NULL)) {
int i;

mms_log_set_type(MMS_LOG_TYPE_STDOUT, "test_mms_codec");
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
mms_log_stdout_timestamp = FALSE;
mms_log_default.level = MMS_LOGLEVEL_INFO;
mms_codec_log.level = MMS_LOGLEVEL_ERR;
}
} else {
/* Default set of test files */
for (i=0; i<G_N_ELEMENTS(default_files); i++) {
if (!test_file(default_files[i])) {
ret = RET_ERR;

ret = RET_OK;
if (argc > 1) {
for (i=1; i<argc; i++) {
if (!test_file(argv[i])) {
ret = RET_ERR;
}
}
} else {
/* Default set of test files */
for (i=0; i<G_N_ELEMENTS(default_files); i++) {
if (!test_file(default_files[i])) {
ret = RET_ERR;
}
}
}
}
g_option_context_free(options);
mms_lib_deinit();
return ret;
}

Expand Down

0 comments on commit 1787cca

Please sign in to comment.