Commit 1787cca4 authored by Slava Monich's avatar Slava Monich

[mms_codec] Ignore broken part headers

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.
parent 7ecde6f7
......@@ -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)\
......
......@@ -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
......@@ -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) {
......
......@@ -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/"
......@@ -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",
......@@ -66,6 +66,7 @@ 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",
......@@ -73,23 +74,49 @@ int main(int argc, char* argv[])
"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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment