summaryrefslogtreecommitdiffstats
path: root/src/gsm
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-01-07 13:39:24 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-01-09 08:22:14 +0100
commit26cbd459fcc7cd7bed8256a5ad078c177a7a7fe2 (patch)
tree0de9217e0d73edd48d3a175680a6824ffd2c77ea /src/gsm
parentd4d87c5427bdf838cbfc3948bcf035e1e4036fd9 (diff)
sms: Fix gsm_7bit legacy functions return value
The legacy 7bit conversion functions (those without the '_n_' in the name) gave wrong return values on 64 bit platforms due to unproper signed/unsigned conversions and the usage of SIZE_MAX. This patch fixes this by using a smaller max size (see GSM_7BIT_LEGACY_MAX_BUFFER_SIZE, currently set to 64k) for the legacy wrappers and by using unsigned int for max_septets. In addition, there are tests now that check the return values of legacy encoding and decoding. Sponsored-by: On-Waves ehf
Diffstat (limited to 'src/gsm')
-rw-r--r--src/gsm/gsm_utils.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index 5241c91c..198ec698 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -273,7 +273,7 @@ int gsm_7bit_encode_n(uint8_t *result, size_t n, const char *data, int *octets)
{
int y = 0;
int o;
- int max_septets = n * 8 / 7;
+ size_t max_septets = n * 8 / 7;
/* prepare for the worst case, every character expanding to two bytes */
uint8_t *rdata = calloc(strlen(data) * 2, sizeof(uint8_t));
@@ -683,7 +683,8 @@ uint32_t gprs_tmsi2tlli(uint32_t p_tmsi, enum gprs_tlli_type type)
int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t septet_l)
{
- gsm_7bit_decode_n(text, SIZE_MAX, user_data, septet_l);
+ gsm_7bit_decode_n(text, GSM_7BIT_LEGACY_MAX_BUFFER_SIZE,
+ user_data, septet_l);
/* Mimic the original behaviour. */
return septet_l;
@@ -691,21 +692,25 @@ int gsm_7bit_decode(char *text, const uint8_t *user_data, uint8_t septet_l)
int gsm_7bit_decode_ussd(char *text, const uint8_t *user_data, uint8_t length)
{
- return gsm_7bit_decode_n_ussd(text, SIZE_MAX, user_data, length);
+ return gsm_7bit_decode_n_ussd(text, GSM_7BIT_LEGACY_MAX_BUFFER_SIZE,
+ user_data, length);
}
int gsm_7bit_encode(uint8_t *result, const char *data)
{
int out;
- return gsm_7bit_encode_n(result, SIZE_MAX, data, &out);
+ return gsm_7bit_encode_n(result, GSM_7BIT_LEGACY_MAX_BUFFER_SIZE,
+ data, &out);
}
int gsm_7bit_encode_ussd(uint8_t *result, const char *data, int *octets)
{
- return gsm_7bit_encode_n_ussd(result, SIZE_MAX, data, octets);
+ return gsm_7bit_encode_n_ussd(result, GSM_7BIT_LEGACY_MAX_BUFFER_SIZE,
+ data, octets);
}
int gsm_7bit_encode_oct(uint8_t *result, const char *data, int *octets)
{
- return gsm_7bit_encode_n(result, SIZE_MAX, data, octets);
+ return gsm_7bit_encode_n(result, GSM_7BIT_LEGACY_MAX_BUFFER_SIZE,
+ data, octets);
}