From bbb11aeb8bd250cbfba96f86a0e79d2ff0901db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdurrahman=20Kaan=20Dike=C3=A7?= Date: Sun, 11 Oct 2026 18:01:42 +0300 Subject: [PATCH] sms delete: only a message index reaches the modem `sms delete ARG` put ARG into AT+CMGD unchecked: anything after the index (a comma flag that deletes more, or another command) went to the modem as it was. Found while the Ubuntu web panel's SMS page was written (#138). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn --- rootfs/overlay/opt/mu300/bin/sms | 2 ++ tests/test_sms_pool.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/rootfs/overlay/opt/mu300/bin/sms b/rootfs/overlay/opt/mu300/bin/sms index a52c1a8c..508ed727 100755 --- a/rootfs/overlay/opt/mu300/bin/sms +++ b/rootfs/overlay/opt/mu300/bin/sms @@ -133,6 +133,8 @@ delete) case $what in all) at 'AT+CMGD=1,4' 30 >/dev/null; echo "deleted every message in $store" ;; read) at 'AT+CMGD=1,1' 30 >/dev/null; echo "deleted the messages already read in $store" ;; + # only a message index reaches the AT command (anything else would be sent to the modem as it is) + *[!0-9]*) echo "sms: not a message index: $what (sms delete INDEX | read | all)" >&2; exit 2 ;; *) at "AT+CMGD=$what" 20 >/dev/null; echo "deleted #$what" ;; esac ;; diff --git a/tests/test_sms_pool.py b/tests/test_sms_pool.py index b5398d6a..2c19d9fb 100644 --- a/tests/test_sms_pool.py +++ b/tests/test_sms_pool.py @@ -713,6 +713,32 @@ class Pool(ShellTest): self.assertEqual((self.tmp / 'fwd.log').read_text().splitlines(), ['enqueue 000001 000002', 'kick']) +class Delete(ShellTest): + """`sms delete` (every system): only a message index, read or all reach the modem.""" + + def setUp(self): + super().setUp() + self.stub('mu300-at', AT_STUB) + (self.tmp / 'at').mkdir() + (self.tmp / 'at' / 'CPMS').write_text('+CPMS: 2,50,2,50,2,50\nOK\n') + + def test_anything_but_an_index_is_refused_before_the_modem(self): + for shell in self.each_shell(): + for bad in ('1;AT+CFUN=0', '1,4', '-1', '1 2', 'x', '1\rAT'): + (self.tmp / 'at.log').unlink(missing_ok=True) + r = subprocess.run(shell + [str(TOP / 'rootfs/overlay/opt/mu300/bin/sms'), 'delete', bad], + capture_output=True, text=True, timeout=30, + env=self.env(MU300_SMS_AWK=AWK, MU300_SMS_STATE=self.tmp / 'state')) + self.assertEqual(r.returncode, 2, (bad, r.stderr)) + log = (self.tmp / 'at.log').read_text() if (self.tmp / 'at.log').exists() else '' + self.assertNotIn('CMGD', log, bad) + r = subprocess.run(shell + [str(TOP / 'rootfs/overlay/opt/mu300/bin/sms'), 'delete', '7'], + capture_output=True, text=True, timeout=30, + env=self.env(MU300_SMS_AWK=AWK, MU300_SMS_STATE=self.tmp / 'state')) + self.assertEqual(r.returncode, 0, r.stderr) + self.assertIn('AT+CMGD=7', (self.tmp / 'at.log').read_text()) + + class Watch(ShellTest): """`sms watch` (every system): a long message waits for its other parts, MU300_SMS_PARTIAL_WAIT at most."""