Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
*/
package com.ibm.engine.language;

import com.ibm.engine.language.c.CCheck;
import com.ibm.engine.language.c.CLanguageSupport;
import com.ibm.engine.language.c.CScanContext;
import com.ibm.engine.language.c.CSymbol;
import com.ibm.engine.language.c.tree.CTree;
import com.ibm.engine.language.csharp.CSharpCheck;
import com.ibm.engine.language.csharp.CSharpLanguageSupport;
import com.ibm.engine.language.csharp.CSharpScanContext;
Expand Down Expand Up @@ -73,4 +78,9 @@ public static ILanguageSupport<GoCheck, Tree, Symbol, GoScanContext> goLanguageS
csharpLanguageSupporter() {
return new CSharpLanguageSupport();
}

@Nonnull
public static ILanguageSupport<CCheck, CTree, CSymbol, CScanContext> cLanguageSupporter() {
return new CLanguageSupport();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Sonar Cryptography Plugin
* Copyright (C) 2024 PQCA
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibm.engine.language.c;

import com.ibm.engine.detection.IBaseMethodVisitor;
import com.ibm.engine.detection.IDetectionEngine;
import com.ibm.engine.detection.TraceSymbol;
import com.ibm.engine.language.c.tree.CBlockTree;
import com.ibm.engine.language.c.tree.CTree;
import javax.annotation.Nonnull;

/**
* Base method visitor for C/C++ that invokes the detection engine on each function body.
*
* <p>Mirrors {@code CSharpBaseMethodVisitor}: when the sensor dispatches a function body (a {@link
* CBlockTree}) via {@link #visitMethodDefinition}, the detection engine is run on it.
*/
public final class CBaseMethodVisitor implements IBaseMethodVisitor<CTree> {

@Nonnull private final TraceSymbol<CSymbol> traceSymbol;
@Nonnull private final IDetectionEngine<CTree, CSymbol> detectionEngine;

public CBaseMethodVisitor(
@Nonnull TraceSymbol<CSymbol> traceSymbol,
@Nonnull IDetectionEngine<CTree, CSymbol> detectionEngine) {
this.traceSymbol = traceSymbol;
this.detectionEngine = detectionEngine;
}

@Override
public void visitMethodDefinition(@Nonnull CTree method) {
if (method instanceof CBlockTree blockTree) {
detectionEngine.run(traceSymbol, blockTree);
}
}
}
34 changes: 34 additions & 0 deletions engine/src/main/java/com/ibm/engine/language/c/CCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Sonar Cryptography Plugin
* Copyright (C) 2024 PQCA
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibm.engine.language.c;

import com.ibm.engine.language.c.tree.CBlockTree;
import javax.annotation.Nonnull;

/**
* Marker interface for C/C++ cryptography detection checks.
*
* <p>Since there is no SonarQube-native C/C++ custom rule API, a custom sensor calls {@link #scan}
* directly for every function body it encounters during parsing.
*/
public interface CCheck {

void scan(@Nonnull CScanContext scanContext, @Nonnull CBlockTree blockTree);
}
Loading