Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Using snprintf() inside Driver

Michael_GrabelkovskyMichael_Grabelkovsky Member Posts: 52
The question is easy: Is it allowed using C run-times such as _snprintf() in Kernel Driver?
Other (sub)question: Is it allowed using _snprintf() on DISPATCH_LEVEL or PASSIVE_LEVEL only?

I got over few sources, including this forum and did not find direct answer on this (simple? :)) questions:

1. Microsoft gives the list of safe string functions which recommend(!!!) replace standard C++ functions. _snprintf() in the list. But this source does not forbid using _snprintf() in Driver.
https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/summary-of-kernel-mode-safe-string-functions

2. The discussion http://www.osronline.com/showThread.cfm?link=36543 references on Walter Owner book with nice table of functions that can be used. snprintf() not in the list.
The last Message 5 of Walter Owner tells:
"You should never use wsprintf anyway, because it can easily overwrite a
buffer. _snwprintf is better but still on the "mildly deprecated" list
because it won't put a null terminator on the target string if the
needed length is >= the length of the target buffer."
But it does not forbid using _snwprintf (and _snwprintf) directly.
Must be noted that this discussion from 2002 year...

What is current real situation with using these function (_snwprintf and _snwprintf) in kernel?
Additional my question 2 about using them on DISPATCH_LEVEL.

Thanks & Regards,
MG.

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 9-13 Sept 2024 Live, Online
Developing Minifilters 15-19 July 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online