Skip to content

Commit

Permalink
added null terminator to message_id in submit_sm_resp
Browse files Browse the repository at this point in the history
  • Loading branch information
ukarim committed Oct 25, 2023
1 parent cfecc31 commit b8af5e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pdu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class SubmitSmRespPdu extends Pdu {
var len = 16;
if (Sts.ok == sts) {
// also need space for message_id
len = len + (messageId != null ? messageId!.length : 0);
len = len + (messageId != null ? (messageId!.length + 1) : 0);
}
var bytes = ByteData(len);
bytes.setUint32(0, len);
Expand All @@ -296,9 +296,7 @@ class SubmitSmRespPdu extends Pdu {
bytes.setUint32(12, seq);
if (Sts.ok == sts && messageId != null) {
int offset = 16;
for (var c in messageId!.codeUnits) {
bytes.setUint8(offset++, c);
}
bytes.setCString(offset, messageId);
}
return bytes;
}
Expand Down
18 changes: 18 additions & 0 deletions pdu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'util.dart';
void main() {
testHeaderPdu();
testBindRespPdu();
testSubmitSmRespPdu();
testDeliverSmPdu();
}

Expand Down Expand Up @@ -42,6 +43,23 @@ void testBindRespPdu() {
);
}

void testSubmitSmRespPdu() {
var expectedBytes = Uint8List.fromList([
0x00, 0x00, 0x00, 0x17,
0x80, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x84,
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x00
]);
var submitSmResp = SubmitSmRespPdu(Sts.ok, 132);
submitSmResp.messageId= "123456";
assertByteDataEquals(
expectedBytes.buffer.asByteData(),
submitSmResp.toBytes(),
"SubmitSmResp incorrectly encoded"
);
}

void testDeliverSmPdu() {
var expectedBytes = Uint8List.fromList([
0x00, 0x00, 0x00, 0x45, // command_length
Expand Down
1 change: 1 addition & 0 deletions smsc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class _DataHandler {

void call(Uint8List byteList) {
try {
// TODO handle partial data
internalCall(byteList);
} catch (e) {
logError("Unexpected error: $e. Closing connection");
Expand Down

0 comments on commit b8af5e0

Please sign in to comment.