Skip to content

Commit 305e9c6

Browse files
committed
Issue #3334: sp_Blitz Fails because of permissions
1 parent cc1f946 commit 305e9c6

1 file changed

Lines changed: 29 additions & 26 deletions

File tree

sp_Blitz.sql

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -306,32 +306,35 @@ AS
306306
BEGIN
307307
SET @SkipValidateLogins = 1;
308308
END; /*Need execute on sp_validatelogins*/
309-
310-
IF EXISTS
311-
(
312-
SELECT 1/0
313-
FROM @db_perms
314-
WHERE database_name = N'model'
315-
)
316-
BEGIN
317-
BEGIN TRY
318-
IF EXISTS
319-
(
320-
SELECT 1/0
321-
FROM model.sys.objects
322-
)
323-
BEGIN
324-
SET @SkipModel = 0; /*We have read permissions in the model database, and can view the objects*/
325-
END;
326-
END TRY
327-
BEGIN CATCH
328-
SET @SkipModel = 1; /*We have read permissions in the model database ... oh wait we got tricked, we can't view the objects*/
329-
END CATCH;
330-
END;
331-
ELSE
332-
BEGIN
333-
SET @SkipModel = 1; /*We don't have read permissions in the model database*/
334-
END;
309+
310+
IF ISNULL(@SkipModel, 0) != 1 /* If @SkipModel hasn't been set to 1 by the caller */
311+
BEGIN
312+
IF EXISTS
313+
(
314+
SELECT 1/0
315+
FROM @db_perms
316+
WHERE database_name = N'model'
317+
)
318+
BEGIN
319+
BEGIN TRY
320+
IF EXISTS
321+
(
322+
SELECT 1/0
323+
FROM model.sys.objects
324+
)
325+
BEGIN
326+
SET @SkipModel = 0; /*We have read permissions in the model database, and can view the objects*/
327+
END;
328+
END TRY
329+
BEGIN CATCH
330+
SET @SkipModel = 1; /*We have read permissions in the model database ... oh wait we got tricked, we can't view the objects*/
331+
END CATCH;
332+
END;
333+
ELSE
334+
BEGIN
335+
SET @SkipModel = 1; /*We don't have read permissions in the model database*/
336+
END;
337+
END;
335338
END;
336339

337340
SET @crlf = NCHAR(13) + NCHAR(10);

0 commit comments

Comments
 (0)