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

[sp_Blitz] DBCC dbinfo fires even if CheckID 68 or 2 is in #SkipChecks #3350

Closed
Montro1981 opened this issue Sep 22, 2023 · 4 comments
Closed
Assignees

Comments

@Montro1981
Copy link
Contributor

Version of the script
Version: 8.16
VersionDate: 20230820

What is the current behavior?
If the user is not part of the sysadmin group @sa gets set to 0:
SET @sa = 0; /*Setting this to 0 to skip DBCC COMMANDS*/

This later ensures that check 68 and 69 are added to #SkipChecks

INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
SELECT
    v.*
FROM (VALUES(NULL, 68, NULL)) AS v (DatabaseName, CheckID, ServerName) /*DBCC command*/
WHERE @sa = 0;

INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
SELECT
    v.*
FROM (VALUES(NULL, 69, NULL)) AS v (DatabaseName, CheckID, ServerName) /*DBCC command*/
WHERE @sa = 0;

But the code checking if DDBC DBInfo can be run has a logical error in it:

--Reformated for readablity
/*
Check 233 is not in #BlitzResults
Check 2 is not in #SkipChecks
Check 68 is in #SkipChecks
*/

IF NOT EXISTS
(
    SELECT 1
    FROM #BlitzResults 
    WHERE CheckID = 223 AND URL = 'https://aws.amazon.com/rds/sqlserver/')
    AND
    (
        NOT EXISTS
        (
            SELECT  1
            FROM    #SkipChecks
            WHERE   DatabaseName IS NULL AND CheckID = 2
        ) OR NOT EXISTS
        (
            SELECT  1
            FROM    #SkipChecks
            WHERE   DatabaseName IS NULL AND CheckID = 68
        )
)

If the current behavior is a bug, please provide the steps to reproduce.
Make a user that is not sysadmin but has VIEW SERVER STATE rights, and doesn't have read rights in some of the system databases
Execute sp_blitz:

EXEC [dbo].[sp_Blitz] 
    @CheckUserDatabaseObjects = 1 ,
    @CheckProcedureCache = 0 ,
    @OutputType = 'TABLE' ,
    @OutputProcedureCache = 0 ,
    @CheckProcedureCacheFilter = NULL,
    @CheckServerInfo = 1 ,
    @Debug = 1

And you'll get these errors:

Extracting DBCC DBINFO data (used in checks 2 and 68).
Msg 2571, Level 14, State 1, Line 9909
User 'guest' does not have permission to run DBCC DBInfo.
Msg 2571, Level 14, State 1, Line 9909
User 'guest' does not have permission to run DBCC DBInfo.
Msg 2571, Level 14, State 1, Line 9909
User 'guest' does not have permission to run DBCC DBInfo.
Msg 2571, Level 14, State 1, Line 9909
User 'SomeUser' does not have permission to run DBCC DBInfo.
Msg 2571, Level 14, State 1, Line 9909
User 'SomeUser' does not have permission to run DBCC DBInfo.

What is the expected behavior?
The DBCC DBInfo is properly excluded if the user is not SA

@Montro1981
Copy link
Contributor Author

Got the code staged and ready to commit, just want to test it a little more.

@Montro1981
Copy link
Contributor Author

The current code works if both 2 and 68 are in de #SkipChecks, also the errors aren't fatal and the procedure will continue to run.

@Montro1981 Montro1981 changed the title [sp_Blitz] DDBC dbinfo fires even if CheckID 68 and/or 2 are in #SkipChecks [sp_Blitz] DDBC dbinfo fires even if CheckID 68 or 2 is in #SkipChecks Sep 22, 2023
@Montro1981 Montro1981 changed the title [sp_Blitz] DDBC dbinfo fires even if CheckID 68 or 2 is in #SkipChecks [sp_Blitz] DBCC dbinfo fires even if CheckID 68 or 2 is in #SkipChecks Sep 22, 2023
Montro1981 added a commit to Montro1981/SQL-Server-First-Responder-Kit that referenced this issue Sep 26, 2023
@Montro1981
Copy link
Contributor Author

Pull request #3357 created

BrentOzar added a commit that referenced this issue Oct 10, 2023
@BrentOzar
Copy link
Member

Thanks for the pull request! Wow, the logic in the original one makes my head hurt. Merging into the dev branch, will be in the next release with credit to you in the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants