# HG changeset patch # User Mychaela Falconia # Date 1691254524 0 # Node ID 0fe95ca922c70b0c84f8a49e64f05a7738bec4ab # Parent 9ed03ed4e673cdd59dd80d30b40421d1b06b502e sms-gen-tpdu: check the high bit of GSM7 msg input diff -r 9ed03ed4e673 -r 0fe95ca922c7 gen-pdu/message.c --- 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 diff -r 9ed03ed4e673 -r 0fe95ca922c7 libcoding/Makefile --- 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} diff -r 9ed03ed4e673 -r 0fe95ca922c7 libcoding/check_high_bit.c --- /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 + +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); +}