4343from ansys .aedt .core .generic .numbers import Quantity
4444from ansys .aedt .core .generic .settings import settings
4545from ansys .aedt .core .internal .aedt_versions import aedt_versions
46+ from ansys .aedt .core .internal .errors import AEDTRuntimeError
4647
4748is_linux = os .name == "posix"
4849is_windows = not is_linux
@@ -918,6 +919,13 @@ def available_license_feature(
918919 feature : str = "electronics_desktop" , input_dir : Union [str , Path ] = None , port : int = 1055 , name : str = "127.0.0.1"
919920) -> int : # pragma: no cover
920921 """Check available license feature.
922+
923+ .. warning::
924+
925+ Do not execute this function with untrusted function argument, environment
926+ variables or pyaedt global settings.
927+ See the :ref:`security guide<ref_security_consideration>` for details.
928+
921929 The method retrieves the port and name values from the ``ANSYSLMD_LICENSE_FILE`` environment variable if available.
922930 If not, the default values are applied.
923931
@@ -939,7 +947,7 @@ def available_license_feature(
939947 int
940948 Number of available license features, ``False`` when license server is down.
941949 """
942- import subprocess # nosec B404
950+ import subprocess # nosec
943951
944952 if os .getenv ("ANSYSLMD_LICENSE_FILE" , None ):
945953 name_env = os .getenv ("ANSYSLMD_LICENSE_FILE" )
@@ -972,11 +980,11 @@ def available_license_feature(
972980
973981 cmd = [str (ansysli_util_path ), "lmstat" , "-f" , feature , "-c" , str (port ) + "@" + str (name )]
974982
975- f = open ( str ( tempfile_checkout ), "w" )
976-
977- subprocess .Popen (cmd , stdout = f , stderr = f , env = my_env ). wait ( ) # nosec
978-
979- f . close ()
983+ try :
984+ with tempfile_checkout . open ( "w" ) as f :
985+ subprocess .run (cmd , stdout = f , stderr = f , env = my_env , check = True ) # nosec
986+ except Exception as e :
987+ raise AEDTRuntimeError ( "Failed to check available licenses" ) from e
980988
981989 available_licenses = 0
982990 pattern_license = r"Total of\s+(\d+)\s+licenses? issued;\s+Total of\s+(\d+)\s+licenses? in use"
0 commit comments