From 1787cca42450eb300475d3b32f4dbdf9f4a2ff7b Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 15 May 2014 12:42:00 +0400 Subject: [PATCH] [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. --- mms-lib/include/mms_lib_log.h | 1 + mms-lib/src/mms_codec.c | 14 ++++- mms-lib/test/mms_codec/data/m-retrieve_9.conf | Bin 0 -> 267 bytes mms-lib/test/mms_codec/test_mms_codec.c | 57 +++++++++++++----- 4 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 mms-lib/test/mms_codec/data/m-retrieve_9.conf diff --git a/mms-lib/include/mms_lib_log.h b/mms-lib/include/mms_lib_log.h index c17950c..fa7cbee 100644 --- a/mms-lib/include/mms_lib_log.h +++ b/mms-lib/include/mms_lib_log.h @@ -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)\ diff --git a/mms-lib/src/mms_codec.c b/mms-lib/src/mms_codec.c index 571663d..2076a95 100644 --- a/mms-lib/src/mms_codec.c +++ b/mms-lib/src/mms_codec.c @@ -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) { diff --git a/mms-lib/test/mms_codec/data/m-retrieve_9.conf b/mms-lib/test/mms_codec/data/m-retrieve_9.conf new file mode 100644 index 0000000000000000000000000000000000000000..2d7a5b87ee4b4a58ccaf5a044241e12a19e4fc98 GIT binary patch literal 267 zcmeBanPFg9=4$HfZV+ndZRulRz|cFXl_j{KV$IBkZgi<>^760V%$@OianI|`Tiz_( z@M=eg!kgs{uXc1QyqVhZx@ikTCtm~4D+3c4U}$UTYU*!nSI@MhE6w^QdRpxN_g?iK~0b#LbGQSf&33=VlSeS*U4$s1oUocnsh z9EG=2XTE8k`)YH`n?*gZ7XmfUYXvHPJz<5O!rPfs-^|_dX4aI~%jYWCg7rdFLo9gH M+z9l@+gUxf08}W5>;M1& literal 0 HcmV?d00001 diff --git a/mms-lib/test/mms_codec/test_mms_codec.c b/mms-lib/test/mms_codec/test_mms_codec.c index 85fc988..cc45986 100644 --- a/mms-lib/test/mms_codec/test_mms_codec.c +++ b/mms-lib/test/mms_codec/test_mms_codec.c @@ -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 1) { + for (i=1; i