Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
La routine DriverEntry deve salvare una copia dell'argomento, non il puntatore, perché Gestione I/O libera il buffer
Commenti
La routine del DriverEntry driver salva una copia del puntatore nel buffer anziché salvare una copia del buffer. Poiché il buffer viene liberato quando la DriverEntry routine restituisce, il puntatore al buffer sarà presto non valido.
Nome analisi del codice: NOT_COPYING_NAME
Esempio
Il codice seguente genera questo avviso.
g_RP è di tipo PUNICODE_STRING, che è un puntatore al tipo di UNICODE_STRINGdati . Salvando , si salva PUNICODE_STRING RegistryPathsolo il puntatore alla UNICODE_STRING posizione in cui esistono i dati. Questa operazione verrà persa alla fine di DriverEntry.
PUNICODE_STRING g_RP;
NTSTATUS
DriverEntry(
PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath
)
{
g_RP = RegistryPath;
return 0;
}
Il codice seguente risolve questo problema.
g_RP è ora un UNICODE_STRINGoggetto , con il proprio buffer. Quando i dati vengono copiati, i dati verranno mantenuti oltre la restituzione di DriverEntry
UNICODE_STRING g_RP;
NTSTATUS
DriverEntry(
PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath
)
{
g_RP = CloneRegistryPath(RegistryPath); // CloneRegistryPath is an example helper function that copies over the data.
return 0;
}