You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First attempt at fixing `Indirect uncontrolled command line` code
scanning alerts for the `index-fils.js` script.
Improves error handling and improves the reliability and security of
code that creates child (exec/spawn) processes.
Attempts to improve the passing of env vars to child processes,
especially for the `LGTM_INDEX_FILTERS` env var.
WIP because CDS extractor invocation is still failing to identify
.cds.json files. Possible problem in the way env vars are passed
within the javascript extractor autobuilder shell script (to the JVM
launched by the javascript extractor autobuilder).
// If the response file does not exist, terminate.
21
+
/**
22
+
* Terminate early if:
23
+
* - the javascript extractor autobuild script does not exist; or
24
+
* - the codeql executable does not exist; or
25
+
* - the input responseFile does not exist; or
26
+
* - the input responseFile is empty or could not be parsed as a list of file paths.
27
+
*/
28
+
if(!existsSync(autobuildScriptPath)){
29
+
console.warn(`'${codeqlExe} database index-files --language cds' terminated early as autobuild script '${autobuildScriptPath}' does not exist.`);
30
+
process.exit(0);
31
+
}
32
+
if(!existsSync(codeqlExePath)){
33
+
console.warn(`'${codeqlExe} database index-files --language cds' terminated early as codeql executable '${codeqlExePath}' does not exist.`);
34
+
process.exit(0);
35
+
}
19
36
if(!existsSync(responseFile)){
20
-
console.log(`'codeql database index-files --language cds' terminated early as response file '${responseFile}' does not exist. This is because no CDS files were selected or found.`);
37
+
console.warn(`'${codeqlExe} database index-files --language cds' terminated early as response file '${responseFile}' does not exist. This is because no CDS files were selected or found.`);
21
38
process.exit(0);
22
39
}
23
40
24
-
// Read the response file and split it into lines, removing (filter(Boolean)) empty lines.
console.log(`'codeql database index-files --language cds' terminated early as response file '${responseFile}' is empty. This is because no CDS files were selected or found.`);
41
+
letresponseFiles=[];
42
+
try{
43
+
// Read the response file and split it into lines, removing (filter(Boolean)) empty lines.
console.warn(`'${codeqlExe} database index-files --language cds' terminated early as response file '${responseFile}' is empty. This is because no CDS files were selected or found.`);
47
+
process.exit(0);
48
+
}
49
+
}catch(err){
50
+
console.warn(`'${codeqlExe} database index-files --language cds' terminated early as response file '${responseFile}' could not be read due to an error: ${err}`);
29
51
process.exit(0);
30
52
}
31
53
32
54
// Determine if we have the cds commands available. If not, install the cds develpment kit
33
55
// (cds-dk) in the appropriate directories and use npx to run the cds command from there.
consterrorMessage=`Could not compile the file ${cdsFilePath}.\nReported error(s):\n\`\`\`\n${stderrTruncated}\n\`\`\``;
94
153
console.log(errorMessage);
95
-
execSync(`${codeqlExePath} database add-diagnostic --extractor-name cds --ready-for-status-page --source-id=cds/compilation-failure --source-name="Failure to compile one or more SAP CAP CDS files" --severity=error --markdown-message="${errorMessage}" --file-path="${cdsFile}" -- "${process.env.CODEQL_EXTRACTOR_CDS_WIP_DATABASE}"`);
154
+
execFileSync(
155
+
codeqlExePath,
156
+
[
157
+
'database',
158
+
'add-diagnostic',
159
+
'--extractor-name=cds',
160
+
'--ready-for-status-page',
161
+
'--source-id=cds/compilation-failure',
162
+
'--source-name="Failure to compile one or more SAP CAP CDS files"',
0 commit comments