From ce1b22e817584d512f82a711c02b67d12346c202 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 4 Aug 2014 14:22:13 +0200 Subject: gprs: Add testcases for the APN string/octet conversion and fix it Create a testcase for the gprs_str_to_apn and gprs_apn_to_str routines. While writing the testcase we noticed it is possible to write more bytes than should have been allowed. This is fixed by checking that the max_len is at least 1 (needed to write the first length octet) and to do the size check before writing to the output. Modify the signature of gprs_str_to_apn to put the length/size next to the parameter that requires a size. Done with Jacob --- openbsc/include/openbsc/gprs_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/include/openbsc') diff --git a/openbsc/include/openbsc/gprs_utils.h b/openbsc/include/openbsc/gprs_utils.h index 1feb0a2e3..2ad5fe490 100644 --- a/openbsc/include/openbsc/gprs_utils.h +++ b/openbsc/include/openbsc/gprs_utils.h @@ -30,4 +30,4 @@ struct msgb *gprs_msgb_copy(const struct msgb *msg, const char *name); int gprs_msgb_resize_area(struct msgb *msg, uint8_t *area, size_t old_size, size_t new_size); char *gprs_apn_to_str(char *out_str, const uint8_t *apn_enc, size_t rest_chars); -int gprs_str_to_apn(uint8_t *apn_enc, const char *str, size_t max_chars); +int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str); -- cgit v1.2.3