aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2014-08-03 23:53:15 +0200
committerPaul Kocialkowski <contact@paulk.fr>2014-08-03 23:53:22 +0200
commitc48926e382b68d0764c88b453711a9b269735537 (patch)
tree9447ac2df240f6083aba76e0ce9be62373fe2385
parent5e4cb302a7e9ccf935c3b47063cbffa389cc9c25 (diff)
downloadexternal_libsamsung-ipc-c48926e382b68d0764c88b453711a9b269735537.zip
external_libsamsung-ipc-c48926e382b68d0764c88b453711a9b269735537.tar.gz
external_libsamsung-ipc-c48926e382b68d0764c88b453711a9b269735537.tar.bz2
sms: Size function for helpers that return data with non-explicit size
Also, pdu is data, not string Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--include/sms.h7
-rw-r--r--samsung-ipc/sms.c59
2 files changed, 57 insertions, 9 deletions
diff --git a/include/sms.h b/include/sms.h
index 5dd4b9f..95b225d 100644
--- a/include/sms.h
+++ b/include/sms.h
@@ -135,9 +135,14 @@ struct ipc_sms_svc_center_addr_header {
* Helpers
*/
+size_t ipc_sms_send_msg_size_setup(struct ipc_sms_send_msg_request_header *header,
+ const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size);
void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header,
const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size);
-char *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size);
+size_t ipc_sms_incoming_msg_pdu_size_extract(const void *data, size_t size);
+void *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size);
+size_t ipc_sms_save_msg_size_setup(struct ipc_sms_save_msg_request_header *header,
+ const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size);
void *ipc_sms_save_msg_setup(struct ipc_sms_save_msg_request_header *header,
const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size);
int ipc_sms_del_msg_setup(struct ipc_sms_del_msg_request_data *data,
diff --git a/samsung-ipc/sms.c b/samsung-ipc/sms.c
index f0e2925..beacecc 100644
--- a/samsung-ipc/sms.c
+++ b/samsung-ipc/sms.c
@@ -23,6 +23,19 @@
#include <samsung-ipc.h>
+size_t ipc_sms_send_msg_size_setup(struct ipc_sms_send_msg_request_header *header,
+ const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size)
+{
+ size_t size;
+
+ if (header == NULL || smsc == NULL || smsc_size == 0 || pdu == NULL || pdu_size == 0)
+ return 0;
+
+ size = sizeof(struct ipc_sms_send_msg_request_header) + sizeof(unsigned char) + smsc_size + pdu_size;
+
+ return size;
+}
+
void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header,
const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size)
{
@@ -36,9 +49,12 @@ void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header,
smsc_length = (unsigned char) smsc_size;
- header->length = (unsigned char) (sizeof(smsc_length) + smsc_size + pdu_size);
+ header->length = (unsigned char) (sizeof(unsigned char) + smsc_size + pdu_size);
+
+ size = ipc_sms_send_msg_size_setup(header, smsc, smsc_size, pdu, pdu_size);
+ if (size == 0)
+ return NULL;
- size = sizeof(struct ipc_sms_send_msg_request_header) + sizeof(smsc_length) + smsc_size + pdu_size;
data = calloc(1, size);
p = (unsigned char *) data;
@@ -58,10 +74,20 @@ void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header,
return data;
}
-char *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size)
+size_t ipc_sms_incoming_msg_pdu_size_extract(const void *data, size_t size)
+{
+ struct ipc_sms_incoming_msg_header *header;
+
+ header = (struct ipc_sms_incoming_msg_header *) data;
+ if (header->length == 0 || header->length > size - sizeof(struct ipc_sms_incoming_msg_header))
+ return 0;
+
+ return (size_t) header->length;
+}
+
+void *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size)
{
struct ipc_sms_incoming_msg_header *header;
- char *string;
void *pdu;
if (data == NULL || size < sizeof(struct ipc_sms_incoming_msg_header))
@@ -73,9 +99,23 @@ char *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size)
pdu = (void *) ((unsigned char *) data + sizeof(struct ipc_sms_incoming_msg_header));
- string = data2string(pdu, header->length);
+ return pdu;
+}
+
+size_t ipc_sms_save_msg_size_setup(struct ipc_sms_save_msg_request_header *header,
+ const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size)
+{
+ size_t size;
+
+ if (header == NULL || pdu == NULL || pdu_size == 0)
+ return 0;
+
+ if (smsc == NULL)
+ smsc_size = 0;
+
+ size = sizeof(struct ipc_sms_save_msg_request_header) + sizeof(unsigned char) + smsc_size + pdu_size;
- return string;
+ return size;
}
void *ipc_sms_save_msg_setup(struct ipc_sms_save_msg_request_header *header,
@@ -96,9 +136,12 @@ void *ipc_sms_save_msg_setup(struct ipc_sms_save_msg_request_header *header,
header->magic = 2;
header->index = 12 - 1,
- header->length = (unsigned char) (sizeof(smsc_length) + smsc_size + pdu_size);
+ header->length = (unsigned char) (sizeof(unsigned char) + smsc_size + pdu_size);
+
+ size = ipc_sms_save_msg_size_setup(header, smsc, smsc_size, pdu, pdu_size);
+ if (size == 0)
+ return NULL;
- size = sizeof(struct ipc_sms_save_msg_request_header) + sizeof(smsc_length) + smsc_size + pdu_size;
data = calloc(1, size);
p = (unsigned char *) data;