clib: Fix possible overflow in subcommand handling