Skip to content

Commit

Permalink
Fix #37: Line numbers in the output doesn't match with the Line numbe…
Browse files Browse the repository at this point in the history
…rs in the source code (#38)

* some fix for linter warnings

* update example of rules with description

* fix row and line numbers on print findings

* change quote to double quotes
  • Loading branch information
htrgouvea authored Feb 19, 2024
1 parent 1acf595 commit 4cf284d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .perlcriticrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
severity = 4
severity = 3

[-TestingAndDebugging::RequireUseStrict]
[-TestingAndDebugging::RequireUseWarnings]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="https://img.shields.io/badge/license-MIT-blue.svg">
</a>
<a href="https://github.com/htrgouvea/zarn/releases">
<img src="https://img.shields.io/badge/version-0.0.9-blue.svg">
<img src="https://img.shields.io/badge/version-0.1.0-blue.svg">
</a>
<br/>
<img src="https://github.com/htrgouvea/zarn/actions/workflows/linter.yml/badge.svg">
Expand Down Expand Up @@ -57,21 +57,22 @@ rules:
- id: '0001'
category: info
name: Debug module enabled
message:
message: Debug modules can expose sensitive information and potentially create security vulnerabilities.
sample:
- Dumper
- id: '0002'
category: vuln
name: Code Injection
message:
message: Occur when untrusted data is executed as code, allowing attackers to run arbitrary commands on the server.
sample:
- system
- eval
- exec
- qx
- id: '0003'
category: vuln
name: Path Traversal
message:
message: Occur when user input is not properly sanitized, allowing attackers to access files and directories outside of the intended directory structure.
sample:
- open
```
Expand All @@ -89,7 +90,7 @@ on:
pull_request:
branches: [ "main" ]
schedule:
- cron: '28 23 * * 1'
- cron: "28 23 * * 1"

jobs:
zarn:
Expand All @@ -114,7 +115,6 @@ jobs:
Your contributions and suggestions are heartily ♥ welcome. [See here the contribution guidelines.](/.github/CONTRIBUTING.md) Please, report bugs via [issues page](https://github.com/htrgouvea/zarn/issues) and for security issues, see here the [security policy.](/SECURITY.md) (✿ ◕‿◕) This project follows this [style guide: (https://github.com/htrgouvea/perl-style-guide)](https://github.com/htrgouvea/perl-style-guide).
---
### License
Expand Down
4 changes: 2 additions & 2 deletions lib/Zarn/AST.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package Zarn::AST {
use PPI::Find;
use PPI::Document;

our $VERSION = '0.01';
our $VERSION = '0.0.1';

sub new {
my ($self, $parameters) = @_;
Expand Down Expand Up @@ -45,7 +45,7 @@ package Zarn::AST {
$var_token -> parent -> isa("PPI::Token::Operator") ||
$var_token -> parent -> isa("PPI::Statement::Expression")
)) {
my ($line, $rowchar) = @{$var_token -> location};
my ($line, $rowchar) = @{$token -> location};

push @results, {
category => $category,
Expand Down
2 changes: 1 addition & 1 deletion lib/Zarn/Files.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Zarn::Files {
use warnings;
use File::Find::Rule;

our $VERSION = '0.01';
our $VERSION = '0.0.1';

sub new {
my ($self, $source, $ignore) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/Zarn/Rules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Zarn::Rules {
use warnings;
use YAML::Tiny;

our $VERSION = '0.01';
our $VERSION = '0.0.1';

sub new {
my ($self, $rules) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/Zarn/Sarif.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package Zarn::Sarif {
use strict;
use warnings;

our $VERSION = '0.01';
our $VERSION = '0.0.1';

sub new {
my ($self, @vulnerabilities) = @_;
Expand Down
25 changes: 12 additions & 13 deletions zarn.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use 5.030;
use strict;
use warnings;
use Carp;
use lib "./lib/";
use Getopt::Long;
use Zarn::AST;
Expand All @@ -25,18 +26,16 @@ sub main {
);

if (!$source) {
print "
\rZarn v0.0.9
\rCore Commands
\r==============
\r\tCommand Description
\r\t------- -----------
\r\t-s, --source Configure a source directory to do static analysis
\r\t-r, --rules Define YAML file with rules
\r\t-i, --ignore Define a file or directory to ignore
\r\t-srf, --sarif Define the SARIF output file
\r\t-h, --help To see help menu of a module\n
\r";
print "\nZarn v0.0.9"
. "\nCore Commands"
. "\n==============\n"
. "\tCommand Description\n"
. "\t------- -----------\n"
. "\t-s, --source Configure a source directory to do static analysis\n"
. "\t-r, --rules Define YAML file with rules\n"
. "\t-i, --ignore Define a file or directory to ignore\n"
. "\t-srf, --sarif Define the SARIF output file\n"
. "\t-h, --help To see help menu of a module\n\n";

exit 1;
}
Expand Down Expand Up @@ -68,7 +67,7 @@ sub main {
if ($sarif) {
my $sarif_data = Zarn::Sarif -> new (@results);

open(my $output, '>', $sarif) or die "Cannot open file '$sarif': $!";
open(my $output, '>', $sarif) or croak "Cannot open file '$sarif': $!";

print $output encode_json($sarif_data);

Expand Down

0 comments on commit 4cf284d

Please sign in to comment.