Skip to content

Commit

Permalink
Merge pull request #47 from Minjung-Baek/master
Browse files Browse the repository at this point in the history
Add .zip file and feature Dexter CLI for Linux
  • Loading branch information
Min-Ho-Kim committed Apr 2, 2016
2 parents 51afcaf + 34b5cf4 commit e213a9e
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public class DexterConfig {
public static final Object FUNCTION_METRICS_BASE ="/functionMetrics/#/";
public static final Object FUNCTION_METRICS_FUNCTION_LIST="functionList";

public static final String SECURITY_CHECK_PREFIX = "sec_";
public static final String EXECUTION_PERMISSION = "chmod 755";
public static final String DEXTER_SCRIPT_NAME = "dexter.sh";
public static final String DEXTER2_SCRIPT_NAME = "dexter2.sh";

/** common constants */
public static final String DEXTER_HOME_KEY = "dexterHome";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class PreOccurence extends BaseDefect {
private String categoryName = "";


public String getCategoryName() {
return categoryName;
}

/**
* @param severityCode the severityCode to set
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.samsung.sec.dexter.core.checker.CheckerConfig;
import com.samsung.sec.dexter.core.config.DexterConfig;
import com.samsung.sec.dexter.core.config.DexterConfig.LANGUAGE;
import com.samsung.sec.dexter.core.exception.DexterRuntimeException;
import com.samsung.sec.dexter.core.plugin.IDexterPlugin;
import com.samsung.sec.dexter.core.plugin.PluginDescription;
import com.samsung.sec.dexter.core.plugin.PluginVersion;
Expand All @@ -55,7 +56,7 @@ public class CppcheckDexterPlugin implements IDexterPlugin {
private PluginDescription pluginDescription;
private CppcheckWrapper cppcheck = new CppcheckWrapper();
private final static Logger logger = Logger.getLogger(CppcheckWrapper.class);

/*
* (non-Javadoc)
*
Expand All @@ -74,6 +75,44 @@ public void destroy() {
// do nothing
}


public boolean checkCppcheckPermission(){
String dexterHome = DexterConfig.getInstance().getDexterHome();

Process changePermissionProcess = null;
StringBuilder changePermissionCmd = new StringBuilder(500);

String dexterBin = dexterHome + DexterUtil.PATH_SEPARATOR + "bin";
String cppcheckHome = dexterBin + DexterUtil.PATH_SEPARATOR + "cppcheck";

if (Strings.isNullOrEmpty(dexterBin)) {
logger.error("Can't initialize Cppcheck plugin, because the dexter_home/bin is not initialized");
return false;
}

if (Strings.isNullOrEmpty(cppcheckHome)) {
logger.error("Can't initialize Cppcheck plugin, because the cppcheckHome is not initialized");
return false;
}


String baseCommand = DexterConfig.EXECUTION_PERMISSION + " ";
changePermissionCmd.append(baseCommand).append(cppcheckHome).append(DexterUtil.PATH_SEPARATOR).append("cppcheck");

try {
changePermissionProcess = Runtime.getRuntime().exec(changePermissionCmd.toString());
} catch (IOException e) {
throw new DexterRuntimeException(e.getMessage() + " changePermissionCmd: " + changePermissionCmd.toString(), e);
}finally {
if(changePermissionProcess != null){
changePermissionProcess.destroy();
}
}

return true;
}


public boolean copyCppcheckRunModule() {
String dexterHome = DexterConfig.getInstance().getDexterHome();
if (Strings.isNullOrEmpty(dexterHome)) {
Expand All @@ -88,10 +127,10 @@ public boolean copyCppcheckRunModule() {
if (DexterUtil.getOS() == DexterUtil.OS.WINDOWS) {
//zipFilePath += "/temp/cppcheck-windows_" + CppcheckDexterPlugin.version.getVersion() + ".zip";
zipFilePath += "/temp/cppcheck-windows_0.9.4.zip";

cppcheckPath = "/cppcheck-windows.zip";
} else {
return true;
} else { // LINUX or MAC
zipFilePath += "/temp/cppcheck-linux_0.9.4.zip";
cppcheckPath = "/cppcheck-linux.zip";
}

final File file = new File(zipFilePath);
Expand All @@ -104,11 +143,7 @@ public boolean copyCppcheckRunModule() {

try {
FileUtils.copyInputStreamToFile(is, file);

if (DexterUtil.getOS() == DexterUtil.OS.WINDOWS) {
DexterUtil.unzip(zipFilePath, dexterHome + CppcheckWrapper.CPPCHECK_HOME_DIR);
} else { // LINUX or MAC
}
DexterUtil.unzip(zipFilePath, dexterHome + CppcheckWrapper.CPPCHECK_HOME_DIR);
} catch (IOException e) {
logger.error(e.getMessage(), e);
return false;
Expand Down Expand Up @@ -160,6 +195,9 @@ public AnalysisResult analyze(final AnalysisConfig config) {
if (bin.exists() == false){
DexterConfig.getInstance().createInitialFolderAndFiles();
copyCppcheckRunModule();
if (DexterUtil.getOS() == DexterUtil.OS.LINUX || DexterUtil.getOS() == DexterUtil.OS.MAC) {
checkCppcheckPermission();
}
}

IAnalysisEntityFactory factory = new AnalysisEntityFactory();
Expand Down Expand Up @@ -210,6 +248,9 @@ public boolean supportLanguage(final LANGUAGE language) {
@Override
public void handleDexterHomeChanged(String oldPath, String newPath) {
copyCppcheckRunModule();
if (DexterUtil.getOS() == DexterUtil.OS.LINUX || DexterUtil.getOS() == DexterUtil.OS.MAC) {
checkCppcheckPermission();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public CheckerConfig getCheckerConfig() {
* cmd.append(" --library=").append(cfgFile).append(" ");
* cmd.append(" 2> ").append(resultFile);
*
* -rp=<path> --rule=<rule>, --rule-file=<file>, --template, -D디파인, -U언디파인
* -rp=<path> --rule=<rule>, --rule-file=<file>, --template, -D�뷀뙆�� -U�몃뵒�뚯씤
*
* @param result void
* @throws Exception
Expand All @@ -93,7 +93,6 @@ public void analyze(final AnalysisResult result){
// 3. Create Command
final StringBuilder cmd = new StringBuilder(500);


setCppcheckCommand(cmd);
setCustomRuleOption(cmd);
cmd.append(" --inconclusive "); // for unreachableCode
Expand All @@ -105,7 +104,6 @@ public void analyze(final AnalysisResult result){
setLanguageOption(cmd);
setHeaderFilesOption(cmd);


// 4. Run Command
Process process = null;
try {
Expand All @@ -129,7 +127,7 @@ public void analyze(final AnalysisResult result){
}
}

private void setCppcheckCommand(final StringBuilder cmd) {
private void setCppcheckCommand(final StringBuilder cmd) {
final String dexterHome = DexterConfig.getInstance().getDexterHome();
final String tempFolder = dexterHome + DexterUtil.PATH_SEPARATOR + "temp";

Expand All @@ -138,21 +136,20 @@ private void setCppcheckCommand(final StringBuilder cmd) {
throw new DexterRuntimeException("Can't create temp folder to save cppcheck result: " + tempFolder);
}
}

final String cppcheckHome = dexterHome + DexterUtil.PATH_SEPARATOR + "bin" + DexterUtil.PATH_SEPARATOR + "cppcheck";
if(new File(cppcheckHome).exists() == false){
throw new DexterRuntimeException("There is no cppcheck home folder : " + cppcheckHome);
}

if(DexterUtil.getOsBit() == DexterUtil.OS_BIT.WIN32 || DexterUtil.getOsBit() == DexterUtil.OS_BIT.WIN64){
cmd.append("cmd /C ");

final String cppcheckHome = dexterHome + DexterUtil.PATH_SEPARATOR + "bin" + DexterUtil.PATH_SEPARATOR + "cppcheck";
if(new File(cppcheckHome).exists() == false){
throw new DexterRuntimeException("There is no cppcheck home folder : " + cppcheckHome);
}

cmd.append(cppcheckHome).append(DexterUtil.PATH_SEPARATOR).append("cppcheck");
cmd.append("cmd /C ").append(cppcheckHome).append(DexterUtil.PATH_SEPARATOR).append("cppcheck");
} else if(DexterUtil.getOsBit() == DexterUtil.OS_BIT.LINUX32 || DexterUtil.getOsBit() == DexterUtil.OS_BIT.LINUX64){
//cmd.append("/bin/bash -c ");
cmd.append("cppcheck");
cmd.append(cppcheckHome).append(DexterUtil.PATH_SEPARATOR).append("cppcheck");
} else {
throw new DexterRuntimeException("This command supports only Windows and Linux('bin/bash')");
}

}

private void setCustomRuleOption(final StringBuilder cmd){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.samsung.sec.dexter.core.analyzer.ResultFileConstant;
import com.samsung.sec.dexter.core.checker.Checker;
import com.samsung.sec.dexter.core.checker.CheckerConfig;
import com.samsung.sec.dexter.core.config.DexterConfig;
import com.samsung.sec.dexter.core.config.DexterConfig.LANGUAGE;
import com.samsung.sec.dexter.core.defect.PreOccurence;
import com.samsung.sec.dexter.core.exception.DexterRuntimeException;
Expand Down Expand Up @@ -87,7 +88,12 @@ public void startElement(final String uri, final String localName, final String

currentOccurence = new PreOccurence();
currentOccurence.setLanguage(LANGUAGE.CPP.toString());
currentOccurence.setMessage(attributes.getValue("verbose").replace("&apos;", "'"));
if(checkerCode.startsWith(DexterConfig.SECURITY_CHECK_PREFIX)){
currentOccurence.setMessage(attributes.getValue("msg").replace("&apos;", "'"));
}
else{
currentOccurence.setMessage(attributes.getValue("verbose").replace("&apos;", "'"));
}
currentOccurence.setToolName(CppcheckDexterPlugin.PLUGIN_NAME);
currentOccurence.setFileName(config.getFileName());
currentOccurence.setModulePath(config.getModulePath());
Expand All @@ -110,7 +116,6 @@ public void startElement(final String uri, final String localName, final String
} else {
setSeverityForNewChecker(attributes, checker);
}

checkerConfig.addChecker(checker);
logger.info("Found new checker(" + checkerCode + ") in " + config.getSourceFileFullPath());
}
Expand Down
Binary file not shown.
Binary file modified project/dexter-cppcheck/src/resource/cppcheck-windows.zip
Binary file not shown.
1 change: 1 addition & 0 deletions project/dexter-executor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Bundle-ClassPath: .,
lib/jspf.remote.xmlrpcdelight-1.0.2.jar,
lib/mockito-all-1.10.19.jar
Export-Package: com.samsung.sec.dexter.executor,
com.samsung.sec.dexter.executor.cli,
org.junit
Require-Bundle: org.eclipse.core.runtime,
dexter-core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,9 @@ private void printDefect(List<Defect> allDefectList) {
etcCnt++;
break;
default:
LOG.errorln("Unknown severity code: " + defect.getSeverityCode() + " / " + defect.getCheckerCode());
defect.setSeverityCode("ETC");
etcCnt++;
break;
}

totalCnt++;
Expand Down
2 changes: 1 addition & 1 deletion project/dexter-findbugs/src/java/checker-config.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ public int visit(IASTDeclaration declaration) {
final Map<String, Integer> mapSourceMatrices = CdtUtilHelper.mapSourceMatrices;
final Map<String, Integer> mapLocSourceMetrices = CdtUtilHelper.mapFunctionLocMetrices;

logger.info(mapSourceMatrices);
logger.info(mapLocSourceMetrices);

final List<Map<String, Object>> functionMetricsMap = new ArrayList<Map<String, Object>>();

for (int i = 0; i < functionList.size(); i++) {
Expand Down
24 changes: 12 additions & 12 deletions project/dexter-vd-cpp/src/java/checker-config.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{"checkerList":
[
{"code":"USLEEP","name":"USEEP for Critical Secure Coding","type":"BOTH","categoryName":"Market Issue","severityCode":"CRI","version":"0.9.2","description":"usleep(useconds_t usec) function can affect system performance, if usec parameter set too shortly. VD recommend that you use more than 10000 ms of usleep function.","isActive":true,"properties":{"value":"10000"},"cwe":0},
{"code":"VECTOR_ERASE_FUNCTION_MISUSE","name":"Vector Erase Function Misuse","type":"BOTH","categoryName":"CRC","severityCode":"MAJ","version":"0.9.2","description":"Avoid vector erase function inside iterative block;","isActive":true,"properties":{"RegExp":"[A-Z][0-9_A-Z]+"},"cwe":3},
{"code":"SIGNED_UNSIGNED_ASSIGNMENT_ERROR","name":"Signed Unsigned Assignment Error","type":"BOTH","categoryName":"CRC","severityCode":"ETC","version":"0.9.2","description":"A Signed data type is transformed into a larger Unsigned data type. This can produce unexpected values.","isActive":true,"properties":{"RegExp":"[A-Z][0-9_A-Z]+"},"cwe":0},
{"code":"CHECK_FREE_STMT","name":"Checking Free Statement for a return object","type":"BOTH","categoryName":"Tizen","severityCode":"CRI","version":"0.9.2","description":"You should have free statement for a returned object by calling ${methodName}","isActive":true,"properties": {"method-list": "vconf_get_str"},"cwe":0},
{"code":"CHECK_FREE_STMT_PARAM", "name": "Checking Free Statement for a parameter object", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.2", "description": "You should have free statement for a parameter by calling ${methodName}", "isActive": true, "properties": { "method-list": "system_info_get_value_string,system_settings_get_value_string" }, "cwe": 0},
{"code":"CHECK_THREAD_UNSAFE_FUNCTION_DBUS_GLIB", "name": "Checking thread unsafe function: dbus-glib", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.2", "description": "${methodName}: dbus-glib is thread unsafe function. so VD recommends NOT to use dbus-glib in the multi-thread environment", "isActive": true, "properties": {"method-list": "dbus_g_proxy_call,dbus_g_proxy_new_for_name,dbus_g_proxy_new_for_owner" }, "cwe": 0},
{"code":"CHECK_USAGE_DUID", "name": "Checking usage of DUID", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.2", "description": "${idName} is used. You need to check usage and the purpose of ID system. please refer to Samsung Smart TV Service Device Identifier Guideline", "isActive": true, "properties": {"id-list": "db/comss/hwduid,db/comss/duid,db/comss/psid"}, "cwe": 0},
{"code":"CHECK_USAGE_ATOI_AS_ARRAY_INDEX","name": "Checking usage of returned value of atoi() as an index of array","type": "BOTH","categoryName": "Tizen","severityCode": "MAJ","version": "0.9.2","description": "atoi() couldreturned return negative value(return type is integer value). do Not use returned value of atoi() as array index without checking its range","isActive": true,"properties": { },"cwe": 0},
{"code":"CHECK_FREE_STMT_THIRD_PARAM", "name": "Checking Free Statement for a parameter object", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.2", "description": "You should have free statement for a parameter by calling ${methodName}", "isActive": true, "properties": {"method-list": "app_control_get_extra_data,app_control_get_extra_data_array"}, "cwe": 0},
{"code":"CHECK_ARRAY_INDEX_OUT_OF_BOUNDS", "name": "Checking array index out of bounds", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.2", "description": "Array index out of bounds", "isActive": true, "properties": { }, "cwe": 129},
{"code": "CHECK_ARRAY_INDEX_OUT_OF_BOUNDS_TWO_DIMESIONAL", "name": "Checking array index out of bounds", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.2", "description": "Array index out of bounds", "isActive": true, "properties": { }, "cwe": 129},
{"code": "DO_WHILE_BRACKET", "name": "Do-While bracket check", "type": "BOTH", "categoryName": "CRC", "severityCode": "CRC", "version": "0.9.2", "description": "In the do-while statement, {} shall be always used", "isActive": true, "properties": { }, "cwe": 0}
{"code":"USLEEP","name":"USEEP for Critical Secure Coding","type":"BOTH","categoryName":"Market Issue","severityCode":"CRI","version":"0.9.4","description":"usleep(useconds_t usec) function can affect system performance, if usec parameter set too shortly. VD recommend that you use more than 10000 ms of usleep function.","isActive":true,"properties":{"value":"10000"},"cwe":0},
{"code":"VECTOR_ERASE_FUNCTION_MISUSE","name":"Vector Erase Function Misuse","type":"BOTH","categoryName":"CRC","severityCode":"MAJ","version":"0.9.4","description":"Avoid vector erase function inside iterative block;","isActive":true,"properties":{"RegExp":"[A-Z][0-9_A-Z]+"},"cwe":3},
{"code":"SIGNED_UNSIGNED_ASSIGNMENT_ERROR","name":"Signed Unsigned Assignment Error","type":"BOTH","categoryName":"CRC","severityCode":"ETC","version":"0.9.4","description":"A Signed data type is transformed into a larger Unsigned data type. This can produce unexpected values.","isActive":true,"properties":{"RegExp":"[A-Z][0-9_A-Z]+"},"cwe":0},
{"code":"CHECK_FREE_STMT","name":"Checking Free Statement for a return object","type":"BOTH","categoryName":"Tizen","severityCode":"CRI","version":"0.9.4","description":"You should have free statement for a returned object by calling ${methodName}","isActive":true,"properties": {"method-list": "vconf_get_str"},"cwe":0},
{"code":"CHECK_FREE_STMT_PARAM", "name": "Checking Free Statement for a parameter object", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.4", "description": "You should have free statement for a parameter by calling ${methodName}", "isActive": true, "properties": { "method-list": "system_info_get_value_string,system_settings_get_value_string" }, "cwe": 0},
{"code":"CHECK_THREAD_UNSAFE_FUNCTION_DBUS_GLIB", "name": "Checking thread unsafe function: dbus-glib", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.4", "description": "${methodName}: dbus-glib is thread unsafe function. so VD recommends NOT to use dbus-glib in the multi-thread environment", "isActive": true, "properties": {"method-list": "dbus_g_proxy_call,dbus_g_proxy_new_for_name,dbus_g_proxy_new_for_owner" }, "cwe": 0},
{"code":"CHECK_USAGE_DUID", "name": "Checking usage of DUID", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.4", "description": "${idName} is used. You need to check usage and the purpose of ID system. please refer to Samsung Smart TV Service Device Identifier Guideline", "isActive": true, "properties": {"id-list": "db/comss/hwduid,db/comss/duid,db/comss/psid"}, "cwe": 0},
{"code":"CHECK_USAGE_ATOI_AS_ARRAY_INDEX","name": "Checking usage of returned value of atoi() as an index of array","type": "BOTH","categoryName": "Tizen","severityCode": "MAJ","version": "0.9.4","description": "atoi() couldreturned return negative value(return type is integer value). do Not use returned value of atoi() as array index without checking its range","isActive": true,"properties": { },"cwe": 0},
{"code":"CHECK_FREE_STMT_THIRD_PARAM", "name": "Checking Free Statement for a parameter object", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.4", "description": "You should have free statement for a parameter by calling ${methodName}", "isActive": true, "properties": {"method-list": "app_control_get_extra_data,app_control_get_extra_data_array"}, "cwe": 0},
{"code":"CHECK_ARRAY_INDEX_OUT_OF_BOUNDS", "name": "Checking array index out of bounds", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.4", "description": "Array index out of bounds", "isActive": true, "properties": { }, "cwe": 129},
{"code": "CHECK_ARRAY_INDEX_OUT_OF_BOUNDS_TWO_DIMESIONAL", "name": "Checking array index out of bounds", "type": "BOTH", "categoryName": "Tizen", "severityCode": "CRI", "version": "0.9.4", "description": "Array index out of bounds", "isActive": true, "properties": { }, "cwe": 129},
{"code": "DO_WHILE_BRACKET", "name": "Do-While bracket check", "type": "BOTH", "categoryName": "CRC", "severityCode": "CRC", "version": "0.9.4", "description": "In the do-while statement, {} shall be always used", "isActive": true, "properties": { }, "cwe": 0}
],
"toolName":"dexter-vd-cpp","language":"CPP"}
Binary file modified project/dexter.eclipse.update.64/artifacts.jar
Binary file not shown.
Binary file modified project/dexter.eclipse.update.64/content.jar
Binary file not shown.
Binary file not shown.
Binary file modified project/dexter.eclipse.update.64/plugins/dexter-core_0.9.4.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified project/dexter.eclipse.update.64/plugins/dexter-eclipse_0.9.4.jar
Binary file not shown.
Binary file not shown.
Binary file modified project/dexter.eclipse.update.64/plugins/dexter-findbugs_0.9.4.jar
Binary file not shown.
Binary file modified project/dexter.eclipse.update.64/plugins/dexter-metrics_0.9.4.jar
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions project/dexter.eclipse.update.64/site.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/dexter.eclipse.feature.64_0.9.4.jar" id="dexter.eclipse.feature.64" version="0.9.4">
<category name="dexter-eclipse"/>
<category name="dexter-eclipse_64"/>
</feature>
<category-def name="dexter-eclipse" label="Dexter Eclipse Feature 64bit">
<category-def name="dexter-eclipse_64" label="Dexter Eclipse Feature 64bit">
<description>
Samsung Electronics VD SE Lab
</description>
Expand Down

0 comments on commit e213a9e

Please sign in to comment.