Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 02cf13d

Browse files
authoredFeb 4, 2020
[CE-1330] Escaping args (#167)
* Escaping args
1 parent bac0787 commit 02cf13d

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ node_modules
2727

2828
lib-cov/
2929
coverage.json
30+
.vs-code

‎lib/codecov.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var urlgrey = require('urlgrey')
55
var jsYaml = require('js-yaml')
66
var walk = require('ignore-walk')
77
var execSync = require('child_process').execSync
8-
var validator = require('validator')
98

109
var detectProvider = require('./detect')
1110

@@ -394,13 +393,13 @@ var upload = function(args, on_success, on_failure) {
394393
if (!isWindows) {
395394
gcov =
396395
'find ' +
397-
(args.options['gcov-root'] || root) +
396+
(sanitizeVar(args.options['gcov-root']) || root) +
398397
" -type f -name '*.gcno' " +
399398
gcg +
400399
' -exec ' +
401-
(validator.escape(args.options['gcov-exec']) || 'gcov') +
400+
(sanitizeVar(args.options['gcov-exec']) || 'gcov') +
402401
' ' +
403-
(validator.escape(args.options['gcov-args']) || '') +
402+
(sanitizeVar(args.options['gcov-args']) || '') +
404403
' {} +'
405404
} else {
406405
// @TODO support for root
@@ -409,9 +408,9 @@ var upload = function(args, on_success, on_failure) {
409408
'for /f "delims=" %g in (\'dir /a-d /b /s *.gcno ' +
410409
gcg +
411410
"') do " +
412-
(args.options['gcov-exec'] || 'gcov') +
411+
(sanitizeVar(args.options['gcov-exec']) || 'gcov') +
413412
' ' +
414-
(args.options['gcov-args'] || '') +
413+
(sanitizeVar(args.options['gcov-args']) || '') +
415414
' %g'
416415
}
417416
debug.push(gcov)
@@ -556,7 +555,12 @@ var upload = function(args, on_success, on_failure) {
556555
}
557556
}
558557

558+
function sanitizeVar(arg) {
559+
return arg.replace(/&/g, '')
560+
}
561+
559562
module.exports = {
563+
sanitizeVar: sanitizeVar,
560564
upload: upload,
561565
version: version,
562566
sendToCodecovV2: sendToCodecovV2,

‎package-lock.json

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
"ignore-walk": "3.0.3",
3636
"js-yaml": "3.13.1",
3737
"teeny-request": "6.0.1",
38-
"urlgrey": "0.4.4",
39-
"validator": "12.2.0"
38+
"urlgrey": "0.4.4"
4039
},
4140
"devDependencies": {
4241
"eslint": "^5.16.0",

‎test/index.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,10 @@ describe('Codecov', function() {
276276
expect(res.query.yaml).toBe(process.cwd() + '/foo.yml')
277277
mockFs.restore()
278278
})
279+
280+
it('can sanitize inputs', function() {
281+
expect(codecov.sanitizeVar('real & run unsafe & command')).toEqual(
282+
'real run unsafe command'
283+
)
284+
})
279285
})

0 commit comments

Comments
 (0)
This repository has been archived.