jackhammer icon indicating copy to clipboard operation
jackhammer copied to clipboard

Adding CPP Checker and Klocwork to Jackhammer

Open vickybyou opened this issue 7 years ago • 4 comments

Hello,

I would like to add the Klocwork and CPP checker to the Jackhammer and take it to the next level. In order to proceed with this i have few queries !!

  1. Does Jackhammer support these tools?
  2. If yes, please suggest me how to proceed further.

Thank you

vickybyou avatar Oct 10 '17 09:10 vickybyou

As of now jackhammer does not support ,we have documented for adding new tool in user-guide . please follow that to integrate new tools

kmadhusudhan avatar Nov 21 '17 08:11 kmadhusudhan

Ok i shall try doing that. If the scanner is already installed in the system there is no need to clone it to the tool directory right ?

vickybyou avatar Nov 21 '17 08:11 vickybyou

yes it is not required

kmadhusudhan avatar Nov 21 '17 09:11 kmadhusudhan

I have added the cppchecker code to /app/lib/pipeline/tasks My CppCheck Code is:

require 'pipeline/tasks/base_task'
require 'pipeline/util'
require 'nokogiri'

class Pipeline::CppChecker < Pipeline::BaseTask
  Pipeline::Tasks.add self
  include Pipeline::Util

  def initialize(trigger, tracker)
    super(trigger, tracker)
    @name = 'CppChecker'
    @description = "A tool for static C/C++ code analysis"
    @stage = :code
    @labels << "code" << "ruby" << "rails"
  end

  def run
    Dir.chdir("#{@trigger.path}") do
    runsystem(true, "cppcheck", "--enable=warning,style,performance,portability", "--force", "--inconclusive", "--xml-version=2", "--output-file=", "#{@results_file.path}", ".")
    @results_file = Tempfile.new(['cppcheckresults', '.xml'])
    @result = File.open("#{@results_file.path}"){ |f| Nokogiri::XML(f) }
    end
  end

  def analyze
    begin
    @result.xpath('//results/errors/error').each do |error|
      bug_type = error['id']
      description = error['msg']
      location = "" #mapping location
      line = "" #mapping line no
      link = ""
      file = ""  #mapping file
      code = ""  #mapping code
      cvss_score = ""
      solution = ""
      advisory = ""
      user_input = ""
      sev = error['severity'] #mapping severity
      case sev
        when "error"
          severity = 'critical'
        when "warning"
          severity = 'high'
        when "style"
          severity = 'medium'
        when "performance", "portability"
          severity = 'low'
        else
          severity = 'Unknown'
      end
      source = {:scanner => @name, :file => file, :line => line, :code => code}
      fprint = fingerprint("#{description}#{bug_type}#{severity}")
      report bug_type,description,source,severity,fprint,link,location,user_input, advisory,solution,cvss_score
    end

  rescue Exception => e
    Pipeline.warn e.message
    Pipeline.warn e.backtrace
  end

ensure
  FileUtils.rm @results_file #file gets deleted after parsing is done
end
  def supported?
  supported=runsystem(true, "cppcheck", "-version")
    if supported =~ /command not found/
    Pipeline.notify "Run: sudo apt-get install cppcheck"
      return false
    else
      return true
    end
  end

end

Later i restarted the tool. As a admin i have enabled CppChecker and later logged out and registered as a new user, since i wont be able to scan repos being an admin. Then added the target: Project title: cpp Source : Github Repo URL : https://github.com/tyranid/ZeroNights2017.git Branch name : master

I got the status as failed. The logs are below.

The log report log/scan/ **[2017-11-28 09:53:19 +0100] Loading scanner... [2017-11-28 09:53:19 +0100] Mounting ... https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:53:19 +0100] Mounting target: https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:53:19 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::DockerMounter:0x00000007a4c408 [2017-11-28 09:53:19 +0100] In Docker mounter, target: https://github.com/tyranid/ZeroNights2017.git became: 017.git ... wondering if it matched .docker [2017-11-28 09:53:19 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::FileSystemMounter:0x00000007a3bb08 [2017-11-28 09:53:19 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::GitMounter:0x00000007a3b108 [2017-11-28 09:53:19 +0100] Mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::GitMounter:0x00000007a3b108 [2017-11-28 09:53:19 +0100] Making base. [2017-11-28 09:53:19 +0100] Cleaning directory: /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:53:19 +0100] Removing : /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:53:19 +0100] Cloning into: /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:53:20 +0100] Mounted https://github.com/tyranid/ZeroNights2017.git with #Pipeline::GitMounter:0x00000007a3b108 [2017-11-28 09:53:20 +0100] Processing target...https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:53:20 +0100] Running tasks in stage: wait [2017-11-28 09:53:20 +0100] Running tasks in stage: mount [2017-11-28 09:53:20 +0100] Running tasks in stage: file [2017-11-28 09:53:20 +0100] Running tasks in stage: code [2017-11-28 09:53:20 +0100] code - CppChecker - #Set:0x00000007c55c68 [2017-11-28 09:53:20 +0100] undefined method `path' for nil:NilClass [2017-11-28 09:53:20 +0100] Running tasks in stage: live [2017-11-28 09:53:20 +0100] Running tasks in stage: done [2017-11-28 09:53:20 +0100] Have 0 items pre ZAP filter. [2017-11-28 09:53:20 +0100] Have 0 items post ZAP filter. [2017-11-28 09:53:20 +0100] Generating report...[:to_s] [2017-11-28 09:53:20 +0100] Running base reoprt... [2017-11-28 09:53:43 +0100] Loading scanner... [2017-11-28 09:53:43 +0100] Mounting ... https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:53:43 +0100] Mounting target: https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:53:43 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::DockerMounter:0x007f8514186488 [2017-11-28 09:53:43 +0100] In Docker mounter, target: https://github.com/tyranid/ZeroNights2017.git became: 017.git ... wondering if it matched .docker [2017-11-28 09:53:43 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::FileSystemMounter:0x007f8514186078 [2017-11-28 09:53:43 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::GitMounter:0x007f8514185e20 [2017-11-28 09:53:43 +0100] Mounting https://github.com/tyranid/ZeroNights2017.git with #Pipeline::GitMounter:0x007f8514185e20 [2017-11-28 09:53:43 +0100] Making base. [2017-11-28 09:53:43 +0100] Cleaning directory: /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:53:43 +0100] Removing : /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:53:43 +0100] Cloning into: /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:53:45 +0100] Mounted https://github.com/tyranid/ZeroNights2017.git with #Pipeline::GitMounter:0x007f8514185e20 [2017-11-28 09:53:45 +0100] Processing target...https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:53:45 +0100] Running tasks in stage: wait [2017-11-28 09:53:45 +0100] Running tasks in stage: mount [2017-11-28 09:53:45 +0100] Running tasks in stage: file [2017-11-28 09:53:45 +0100] Running tasks in stage: code [2017-11-28 09:53:45 +0100] code - CppChecker - #Set:0x007f84a80c9430

[2017-11-28 09:53:45 +0100] Running tasks in stage: live [2017-11-28 09:53:45 +0100] Running tasks in stage: done [2017-11-28 09:53:45 +0100] Have 0 items pre ZAP filter. [2017-11-28 09:53:45 +0100] Have 0 items post ZAP filter. [2017-11-28 09:53:45 +0100] Generating report...[:to_s] [2017-11-28 09:53:45 +0100] Running base reoprt... [2017-11-28 09:54:46 +0100] Loading scanner... [2017-11-28 09:54:46 +0100] Mounting ... https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:54:46 +0100] Mounting target: https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:54:46 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #<:dockermounter:0x00000008a6f600> [2017-11-28 09:54:46 +0100] In Docker mounter, target: https://github.com/tyranid/ZeroNights2017.git became: 017.git ... wondering if it matched .docker [2017-11-28 09:54:46 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #<:filesystemmounter:0x00000008a6f1c8> [2017-11-28 09:54:46 +0100] Checking about mounting https://github.com/tyranid/ZeroNights2017.git with #<:gitmounter:0x00000008a6ef70> [2017-11-28 09:54:46 +0100] Mounting https://github.com/tyranid/ZeroNights2017.git with #<:gitmounter:0x00000008a6ef70> [2017-11-28 09:54:46 +0100] Making base. [2017-11-28 09:54:46 +0100] Cleaning directory: /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:54:46 +0100] Removing : /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:54:46 +0100] Cloning into: /home/vikas/line/tmp/github.com/tyranid/ZeroNights2017 [2017-11-28 09:54:47 +0100] Mounted https://github.com/tyranid/ZeroNights2017.git with #<:gitmounter:0x00000008a6ef70> [2017-11-28 09:54:47 +0100] Processing target...https://github.com/tyranid/ZeroNights2017.git [2017-11-28 09:54:47 +0100] Running tasks in stage: wait [2017-11-28 09:54:47 +0100] Running tasks in stage: mount [2017-11-28 09:54:47 +0100] Running tasks in stage: file [2017-11-28 09:54:47 +0100] Running tasks in stage: code [2017-11-28 09:54:47 +0100] code - CppChecker - #<0x000000089fb408>

>"">"""">"""">"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""<>"""""""""""""""""""""""""""""""""""""<>

vickybyou avatar Nov 21 '17 11:11 vickybyou