aboutsummaryrefslogtreecommitdiffstats
path: root/tests/ussd
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-10-11 07:56:06 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-10-11 09:25:14 +0200
commitdaa653fc2268ca99389ef2730abf5fe000eb7a37 (patch)
treec50a66012f9f882c0e41fd34567b54cfacb73741 /tests/ussd
parent00cb5700e65ef8bf4e86bdb0b45084265d73e5d9 (diff)
ussd: Add a test case, switch parsing to use a gsm48_hdr and len
The current USSD code is not doing any size checks, add a test case to find out how easily we access the data out of bounds. Begin to use the length in some places.
Diffstat (limited to 'tests/ussd')
-rw-r--r--tests/ussd/Makefile.am5
-rw-r--r--tests/ussd/ussd_test.c63
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/ussd/Makefile.am b/tests/ussd/Makefile.am
new file mode 100644
index 00000000..d29506cc
--- /dev/null
+++ b/tests/ussd/Makefile.am
@@ -0,0 +1,5 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+noinst_PROGRAMS = ussd_test
+
+ussd_test_SOURCES = ussd_test.c
+ussd_test_LDADD = $(top_builddir)/src/libosmocore.la
diff --git a/tests/ussd/ussd_test.c b/tests/ussd/ussd_test.c
new file mode 100644
index 00000000..4d125ffd
--- /dev/null
+++ b/tests/ussd/ussd_test.c
@@ -0,0 +1,63 @@
+/*
+ * (C) 2010 by Holger Hans Peter Freyther
+ * (C) 2010 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <osmocore/gsm0480.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const uint8_t ussd_request[] = {
+ 0x0b, 0x7b, 0x1c, 0x15, 0xa1, 0x13, 0x02, 0x01,
+ 0x03, 0x02, 0x01, 0x3b, 0x30, 0x0b, 0x04, 0x01,
+ 0x0f, 0x04, 0x06, 0x2a, 0xd5, 0x4c, 0x16, 0x1b,
+ 0x01, 0x7f, 0x01, 0x00
+};
+
+static int parse_ussd(const uint8_t *_data, int len)
+{
+ uint8_t *data;
+ int rc;
+ struct ussd_request req;
+ struct gsm48_hdr *hdr;
+
+ data = malloc(len);
+ memcpy(data, _data, len);
+ hdr = (struct gsm48_hdr *) &data[0];
+ rc = gsm0480_decode_ussd_request(hdr, len, &req);
+ free(data);
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ const int size = sizeof(ussd_request);
+ int i;
+
+ printf("Testing parsing a USSD request and truncated versions\n");
+
+ for (i = size; i > sizeof(struct gsm48_hdr); --i) {
+ int rc = parse_ussd(&ussd_request[0], i);
+ printf("Result for %d is %d\n", rc, i);
+ }
+
+ return 0;
+}