Re[4]: strcpy in DDK

Is this so strange or difficult?

Damn, your not stomping your feet are you?

m.
----- Original Message -----
From: “Shadow”
> To: “Windows System Software Devs Interest List”
> Sent: Friday, July 28, 2006 7:27 AM
> Subject: Re[2]: [ntdev] strcpy in DDK

>> No.
>> The handle leads to a file which stores the data.
>> I want it to store data in a string variable.
>> I changed the device extension structure, so that there is no handle
>> now, just a string variable.
>>
>>
>> ---------------------------------------------------------------------
>> Hi, All.
>>
>> Need your help(due to my newbity in DDK).
>> I have a device driver, that I’m trying to modify.
>>
>> It sets up a devise extension, used to store data.
>> typedef struct _DEVICE_EXTENSION
>> {
>> …
>> HANDLE hLogFile;
>> …
>> }
>> hLogFile manages a log file created by ZwCreateFile.
>>
>> But I want it to store data in some string variable for further
>> operations.
>>
>> So, I’ve changed ‘HANDLE hLogFile’ to ‘char hLogFile[4096]’.
>>
>> After that I found where the code calls hLogFile.
>> Here it is:
>> char vals[3]={0};
>> …
>>
> ZwCreateFile(pDevExt->hLogFile,NULL,NULL,NULL,&io_status,&vals,strlen(vals),
> NULL,NULL);
>> And changed that to:
>> char vals[3]={0};
>> …
>> strcpy(pKeyboardDeviceExtension->hLogFile,vals);
>>
>> But after my changes the driver just crashes the system to reboot.
>>
>>
>> Any ideas?
>>
>> ---------------------------------------------------------------------
>>
>> > what data do u want to modify? The handle!!! — Questions? First
>> > check the Kernel Driver FAQ at
>> > http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit
>> > the List Server section of OSR Online at
>> > http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>>
>> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256

> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

> Is this so strange or difficult?

No, and the level of misunderstanding in the responses is astounding.
However you are asking basically a C programming 101 question.

You appear to have, from the information you provided:

char vals[3]={0};
char hLogFile[4096];

strcpy(hLogFile, vals);

Upon the execution of which it seems the system crashes. Might I suggest a
debugger?

There have been some useful suggestions. Examine your code and make sure
that all references to the now misnamed hLogFile are treating it as its new
char array type rather than its old handle type. Consider renaming hLogFile
to something more appropriate such as LogArray or LogBuffer.

Vals had better be a null terminated string when you invoke strcpy as
otherwise you are likely to have a system crash. Consider strncpy as well,
as hLogFile is a bounded array. In fact see the DDK for information on Safe
String Functions.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Shadow
Sent: Friday, July 28, 2006 9:00 AM
To: Windows System Software Devs Interest List
Subject: Re[4]: [ntdev] strcpy in DDK

Is this so strange or difficult?

> Damn, your not stomping your feet are you?

> m.
> ----- Original Message -----
> From: “Shadow”
> > To: “Windows System Software Devs Interest List”
>
> > Sent: Friday, July 28, 2006 7:27 AM
> > Subject: Re[2]: [ntdev] strcpy in DDK
>
>
> >> No.
> >> The handle leads to a file which stores the data.
> >> I want it to store data in a string variable.
> >> I changed the device extension structure, so that there is
> no handle
> >> now, just a string variable.
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> Hi, All.
> >>
> >> Need your help(due to my newbity in DDK).
> >> I have a device driver, that I’m trying to modify.
> >>
> >> It sets up a devise extension, used to store data.
> >> typedef struct _DEVICE_EXTENSION
> >> {
> >> …
> >> HANDLE hLogFile;
> >> …
> >> }
> >> hLogFile manages a log file created by ZwCreateFile.
> >>
> >> But I want it to store data in some string variable for further
> >> operations.
> >>
> >> So, I’ve changed ‘HANDLE hLogFile’ to ‘char hLogFile[4096]’.
> >>
> >> After that I found where the code calls hLogFile.
> >> Here it is:
> >> char vals[3]={0};
> >> …
> >>
> >
> ZwCreateFile(pDevExt->hLogFile,NULL,NULL,NULL,&io_status,&vals,strlen(
> > vals),
> > NULL,NULL);
> >> And changed that to:
> >> char vals[3]={0};
> >> …
> >> strcpy(pKeyboardDeviceExtension->hLogFile,vals);
> >>
> >> But after my changes the driver just crashes the system to reboot.
> >>
> >>
> >> Any ideas?
> >>
> >>
> ---------------------------------------------------------------------
> >>
> >> > what data do u want to modify? The handle!!! —
> Questions? First
> >> > check the Kernel Driver FAQ at
> >> > http://www.osronline.com/article.cfm?id=256 To
> unsubscribe, visit
> >> > the List Server section of OSR Online at
> >> > http://www.osronline.com/page.cfm?name=ListServer
> >>
> >>
> >>
> >>
> >> —
> >> Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >>
> >> To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
>
>
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
>
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online
> at http://www.osronline.com/page.cfm?name=ListServer
>