Preparing the System for Cross-Platform Query Support (v9.3.0)

There are differences between Windows and Linux with respect to file names and new line characters. Therefore, CxSAST queries have been adjusted to run run on Windows and Linux. User custom queries must follow the same adaptations to support both platforms as explained below.

Required Adjustments

There are two differences between Linux and Windows:

  1. File names:

    1. Windows – *\temp\config.xml

    2. Linux – */temp/config.xml

  2. New Line characters:

    1. Windows - \r\n

    2. Linux  - \n

Solution

Already starting with CxSAST 9.2, an additional CxQL API has been introduced, the cxEnv. By using this API variable, queries can be written in a cross-platform format in order to support both operating systems.

There are 6 properties to be used in cxEnv:

  • cxEnv.Path.DirectorySeparatorChar

  • cxEnv.Path.AltDirectorySeparatorChar

  • cxEnvPath.InvalidPathChars

  • cxEnv.Path.PathSeparator

  • cxEnv.Path.VolumeSeparatorChar

  • cxEnv.NewLine

For a full description of each variable, refer to the latest CxQL API guide.

All custom queries must use the above-listed variables rather than the actual values to run on both platforms and all their flavors.

Examples

The following section illustrates two examples.

Directory Separator

This string:

string[] path = fileName.Split('\\');

Must be replaced with the following:

string[] path = fileName.Split(cxEnv.Path.DirectorySeparatorChar);

New Line in Regex

This string:

elseIfs.FindByRegex(@"[\W]if[^;\{]*{[^\}]*}[(\s)(\r\n)]*else[(\s)(\r\n)]*{[^\}]*?[(/\*)(//)]");

Must be replaced with the following: