FreeCalypso > hg > sms-coding-utils
changeset 12:0fe95ca922c7
sms-gen-tpdu: check the high bit of GSM7 msg input
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 16:55:24 +0000 |
parents | 9ed03ed4e673 |
children | b8d8f8a3cdb7 |
files | gen-pdu/message.c libcoding/Makefile libcoding/check_high_bit.c |
diffstat | 3 files changed, 28 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/gen-pdu/message.c Sat Aug 05 08:44:32 2023 +0000 +++ b/gen-pdu/message.c Sat Aug 05 16:55:24 2023 +0000 @@ -111,6 +111,11 @@ udh_chars = 0; } plain_chars = input_len - udhl1; + if (check_high_bit(input + udhl1, plain_chars) < 0) { + fprintf(stderr, ERR_PREFIX "high bit set in GSM7 data\n", + input_lineno); + exit(1); + } udl = udh_chars + plain_chars; if (udl > 160) { fprintf(stderr, ERR_PREFIX
--- a/libcoding/Makefile Sat Aug 05 08:44:32 2023 +0000 +++ b/libcoding/Makefile Sat Aug 05 16:55:24 2023 +0000 @@ -1,7 +1,8 @@ CC= gcc CFLAGS= -O2 -OBJS= gsm7_encode.o gsm7_encode_table.o gsm7_pack.o hexdigits.o hexout.o \ - number_encode.o timestamp.o ucs2_bigend.o utf8_decode.o utf8_decode2.o +OBJS= check_high_bit.o gsm7_encode.o gsm7_encode_table.o gsm7_pack.o \ + hexdigits.o hexout.o number_encode.o timestamp.o ucs2_bigend.o \ + utf8_decode.o utf8_decode2.o LIB= libcoding.a all: ${LIB}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/check_high_bit.c Sat Aug 05 16:55:24 2023 +0000 @@ -0,0 +1,20 @@ +/* + * The function implemented in this module is intended for validating inputs + * that are expected to be in the form of GSM7 characters carried in an octet + * string, where the high bit of every octet is expected to be cleared. + */ + +#include <sys/types.h> + +check_high_bit(buf, len) + u_char *buf; + unsigned len; +{ + unsigned n; + + for (n = 0; n < len; n++) { + if (buf[n] & 0x80) + return(-1); + } + return(0); +}