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
26 changes: 26 additions & 0 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
workflow_dispatch: {}
pull_request: {}
push:
branches:
- main
- master
paths:
- .github/workflows/semgrep.yml
schedule:
# random HH:MM to avoid a load spike on GitHub Actions at 00:00
- cron: 23 9 * * *
name: Semgrep
jobs:
semgrep:
name: semgrep/ci
runs-on: ubuntu-latest
permissions:
contents: read
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
container:
image: semgrep/semgrep
steps:
- uses: actions/checkout@v4
- run: semgrep ci
32 changes: 32 additions & 0 deletions src/main/java/org/owasp/benchmark/helpers/Thing2.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
*/
package org.owasp.benchmark.helpers;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class Thing2 implements ThingInterface {

@Override
Expand All @@ -25,4 +31,30 @@ public String doSomething(String i) {
String r = new StringBuilder(i).toString();
return r;
}

// Violates S112: Generic exceptions should not be thrown
public String processInput(String input) throws Exception {
if (input == null) {
throw new Exception("Input must not be null");
}
return input.trim();
}

// Violates S1168: Return empty collection instead of null
public List<String> getItems(String category) {
if (category == null) {
return null;
}
return new ArrayList<>();
}

// Violates S2095: Resources should be closed
public int countBytes(String filePath) throws IOException {
InputStream stream = new FileInputStream(filePath);
int count = 0;
while (stream.read() != -1) {
count++;
}
return count;
}
}