Fix illegal shell characters

This change checks if the user input is legal.
if illegal, we raise an InvalidValue excepiton.

Story: 2010004
Task: 45128

Change-Id: Ib81646b8f8a01fcbc31d033ec205491b76a7b755
This commit is contained in:
wu.chunyang
2022-09-06 21:03:25 +08:00
committed by wu.chunyang
parent af1db229b9
commit 0ec4d0487b
5 changed files with 40 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
from collections import abc
import inspect
import os
import shlex
import shutil
import uuid
import urllib.parse as urlparse
@@ -423,3 +424,13 @@ def req_to_text(req):
parts.extend([b'', safe_encode(req.body)])
return b'\r\n'.join(parts).decode(req.charset)
def validate_command(string):
"""
Check if the string is legal for command
raise invalidvalue if illegal
"""
if string != shlex.quote(string):
raise exception.InvalidValue(value=string)