Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #37: Line numbers in the output doesn't match with the Line numbers in the source code #38

Merged
merged 5 commits into from
Feb 19, 2024
Merged
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
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 @@
use PPI::Find;
use PPI::Document;

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

sub new {
my ($self, $parameters) = @_;
Expand Down Expand Up @@ -40,12 +40,12 @@
sub { $_[1] -> isa("PPI::Token::Symbol") and $_[1] -> content eq "\$$1" }
);

if ($var_token && $var_token -> can("parent")) {

Check failure on line 43 in lib/Zarn/AST.pm

View workflow job for this annotation

GitHub Actions / critic

Code structure is deeply nested at line 43, column 29. Consider refactoring.
if ((

Check failure on line 44 in lib/Zarn/AST.pm

View workflow job for this annotation

GitHub Actions / critic

Code structure is deeply nested at line 44, column 33. Consider refactoring.
$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