-
Notifications
You must be signed in to change notification settings - Fork 302
Fix database mssql mode deadlocks #6127
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
base: develop
Are you sure you want to change the base?
Changes from 3 commits
bcfd5e7
e41db71
864f2d1
40cfc43
2c9b781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,11 @@ | |
|
|
||
| package database::mssql::mode::lockswaits; | ||
|
|
||
| use base qw(centreon::plugins::templates::counter); | ||
|
|
||
| use strict; | ||
| use warnings; | ||
| use base qw(centreon::plugins::templates::counter); | ||
| use Digest::MD5 qw(md5_hex); | ||
|
|
||
| sub set_counters { | ||
| my ($self, %options) = @_; | ||
|
|
@@ -32,8 +34,8 @@ sub set_counters { | |
| ]; | ||
|
|
||
| $self->{maps_counters}->{lockswaits} = [ | ||
| { label => 'lockswaits', nlabel => 'mssql.lockswaits.count', set => { | ||
| key_values => [ { name => 'value' } ], | ||
| { label => 'lockswaits', nlabel => 'mssql.lockswaits.count.persecond', set => { | ||
| key_values => [ { name => 'value', per_second => 1 } ], | ||
| output_template => '%.2f locks waits/s', | ||
| perfdatas => [ | ||
| { template => '%.2f', min => 0 } | ||
|
|
@@ -46,11 +48,11 @@ sub set_counters { | |
|
|
||
| sub new { | ||
| my ($class, %options) = @_; | ||
| my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); | ||
| my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); | ||
| bless $self, $class; | ||
|
|
||
| $options{options}->add_options(arguments => { | ||
| 'filter-database:s' => { name => 'filter_database' } | ||
| 'filter-instance:s' => { name => 'filter_instance', default => '_Total' } | ||
| }); | ||
|
|
||
| return $self; | ||
|
|
@@ -67,18 +69,21 @@ sub manage_selection { | |
| sys.dm_os_performance_counters | ||
| WHERE | ||
| object_name = 'SQLServer:Locks' | ||
| AND | ||
| counter_name LIKE 'Lock Waits/sec%' | ||
| AND counter_name LIKE 'Lock Waits/sec%' | ||
| }); | ||
|
|
||
| my $query_result = $options{sql}->fetchall_arrayref(); | ||
| $self->{lockswaits}->{value} = 0; | ||
|
|
||
| foreach my $row (@{$query_result}) { | ||
| next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' | ||
| && $$row[0] !~ /$self->{option_results}->{filter_database}/); | ||
| next if (defined($self->{option_results}->{filter_instance}) && $self->{option_results}->{filter_instance} ne '' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User-provided filter_instance is directly interpolated into a regex ($$row[0] !~ /$self->{option_results}->{filter_instance}/), enabling regex injection or ReDoS. Validate or escape (e.g., quotemeta) filter_instance before use. Details✨ AI Reasoning 🔧 How do I fix it? Reply |
||
| && $$row[0] !~ /$self->{option_results}->{filter_instance}/); | ||
| $self->{lockswaits}->{value} += $$row[1]; | ||
| } | ||
|
|
||
| $self->{cache_name} = 'mssql_' . $self->{mode} . '_' . | ||
| (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . | ||
| (defined($self->{option_results}->{filter_instance}) ? md5_hex($self->{option_results}->{filter_instance}) : md5_hex('all')); | ||
| } | ||
|
|
||
| 1; | ||
|
|
@@ -99,9 +104,10 @@ Warning threshold number of lock-waits per second. | |
|
|
||
| Critical threshold number of lock-waits per second. | ||
|
|
||
| =item B<--filter-database> | ||
| =item B<--filter-instance> | ||
|
|
||
| Filter the databases to monitor with a regular expression. | ||
| Filter the sub-category inside the performance object. The instance_name represents the lock type. For example: C<_Total>, C<DATABASE>, C<OBJECT>, C<PAGE>, C<KEY>. (default: '_Total') | ||
| https://learn.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-locks-object?view=sql-server-ver17 | ||
|
|
||
| =back | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User-provided filter_instance is directly interpolated into a regex ($$row[0] !~ /$self->{option_results}->{filter_instance}/), enabling regex injection or ReDoS. Validate or escape (e.g., quotemeta) filter_instance before use.
Details
✨ AI Reasoning
The code now uses the CLI option filter_instance (defaulting to '_Total' but still user-controlled) directly inside a Perl regex match: $$row[0] !~ /$self->{option_results}->{filter_instance}/. Interpolating unvalidated user input into a regex can lead to regex injection, syntax errors, or ReDoS issues. This was introduced by the PR when replacing filter_database with filter_instance and should be flagged. The problematic expression appears in the newly added filtering logic in both changed files.
🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.
Reply
@AikidoSec feedback: [FEEDBACK]to get better review comments in the future.Reply
@AikidoSec ignore: [REASON]to ignore this issue.More info