CLI: Ensure IDs are non-zero

This fixes out-of-bounds accesses in several subcommands when the
invalid ID @0 is passed to the program.
This commit is contained in:
Janik Rabe 2018-08-06 14:06:04 +03:00 committed by lauft
parent 9489ed5b70
commit 48aa9cfdc0
2 changed files with 6 additions and 1 deletions

View file

@ -412,7 +412,8 @@ void CLI::identifyIds ()
int digits;
if (pig.skipLiteral ("@") &&
pig.getDigits (digits) &&
pig.eos ())
pig.eos () &&
digits > 0)
{
a.tag ("ID");
a.attribute ("value", digits);

View file

@ -48,6 +48,10 @@ class TestIds(TestCase):
self.assertIn(' @1 ', out)
self.assertIn(' @2 ', out)
def test_should_fail_on_zero_id(self):
code, out, err = self.t.runError("delete @0")
self.assertIn("IDs must be specified.", err)
if __name__ == "__main__":
from simpletap import TAPTestRunner