Skip to content

Commit

Permalink
using Open3.popen3 library
Browse files Browse the repository at this point in the history
Signed-off-by: Aishwarya Aishwarya <aaishwar@progress.com>
  • Loading branch information
Aishwarya2001A committed Oct 9, 2024
1 parent 858ff30 commit 55f338c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions scripts/git_difference_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ def valid_sha1?(sha)

# Use the hard-coded git command and append dev_rev if it's valid
command = GIT_COMMAND + [dev_rev]
# Securely execute the command using Open3
stdout, stderr, status = Open3.capture3(*command)
dev_rev_invalid = !status.success?

if dev_rev_invalid
STDERR.puts("DEBUG: git cat-file failed for dev_rev: #{dev_rev}")
STDERR.puts("ERROR: #{stderr.strip}")
else
STDERR.puts("DEBUG: git cat-file succeeded for dev_rev: #{dev_rev}")

# Execute the command and capture output
Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|

Check failure

Code scanning / CodeQL

Uncontrolled command line Critical

This command depends on a
user-provided value
.
dev_rev_invalid = !wait_thr.value.success?
stdout_str = stdout.read
stderr_str = stderr.read

if dev_rev_invalid
STDERR.puts("DEBUG: git cat-file failed for dev_rev: #{dev_rev}")
STDERR.puts("ERROR: #{stderr_str.strip}")
else
STDERR.puts("DEBUG: git cat-file succeeded for dev_rev: #{dev_rev}")
end
end
else
STDERR.puts("WARNING: Invalid dev_rev SHA-1: #{dev_rev}")
Expand Down

0 comments on commit 55f338c

Please sign in to comment.