Anand
Anand

Reputation: 116

Access violation executing location - GetFileAttributesA

I am having a peculiar problem with GetFileAttributedA on Windows 8.1 x64 on VS2012. The functions runs fine, but once in a while the statement crashes with

Unhandled exception at 0x00000003 in MyService.exe: 0xC0000005: Access violation executing location 0x00000003.

Here is the pseudo code.

char    szItemAbsPath[MAX_PATH];
DWORD   rc = 0;
DWORD   dwFileAttribute = 0;

memset(szItemAbsPath, '\0', sizeof(szItemAbsPath));
sprintf(szItemAbsPath, "%s%s%s", "D:\\Root", FILE_SEPARATOR_STR, "temp.txt");

// check item type
dwFileAttribute = GetFileAttributesA(szItemAbsPath); //this is where program crashes
if (dwFileAttribute == INVALID_FILE_ATTRIBUTES)
{
    rc = GetLastError();
        return rc;
}

if (dwFileAttribute & FILE_ATTRIBUTE_DIRECTORY)
{
    // this is a dir
}

I basically want to check if a given item is a file or folder. This problem is sometimes observed in 32bit builds too.

Edited:

MiniDump

Dump Summary
------------
Dump File:  MyDesktopService.dmp : C:\Users\anand\Desktop\MyDesktopService.dmp
Last Write Time:    09-04-2014 17:34:24
Process Name:   MyDesktopService.exe : D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MyDesktopService.exe
Process Architecture:   x86
Exception Code: 0xC0000005
Exception Information:  The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
Heap Information:   Present

System Information
------------------
OS Version: 6.2.9200
CLR Version(s): 

Modules
-------
Module Name Module Path Module Version
----------- ----------- --------------
MyDesktopService.exe    D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MyDesktopService.exe 0.0.0.0
ntdll.dll   C:\Windows\System32\ntdll.dll   6.3.9600.16502
kernel32.dll    C:\Windows\System32\kernel32.dll    6.3.9600.16520
KERNELBASE.dll  C:\Windows\System32\KERNELBASE.dll  6.3.9600.16496
MSVCR110D.dll   D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MSVCR110D.dll    11.0.51106.1
MyDesktop.dll   D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MyDesktop.dll    0.0.0.0
libeay32.dll    D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\libeay32.dll 1.0.1.6
wtsapi32.dll    C:\Windows\System32\wtsapi32.dll    6.3.9600.16384
userenv.dll C:\Windows\System32\userenv.dll 6.3.9600.16384
advapi32.dll    C:\Windows\System32\advapi32.dll    6.3.9600.16384
ws2_32.dll  C:\Windows\System32\ws2_32.dll  6.3.9600.16384
libcurl_debug.dll   D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\libcurl_debug.dll    7.34.0.0
jansson.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\jansson.dll  0.0.0.0
gdi32.dll   C:\Windows\System32\gdi32.dll   6.3.9600.16421
user32.dll  C:\Windows\System32\user32.dll  6.3.9600.16441
msvcr110.dll    C:\Windows\System32\msvcr110.dll    11.0.51106.1
msvcrt.dll  C:\Windows\System32\msvcrt.dll  7.0.9600.16384
rpcrt4.dll  C:\Windows\System32\rpcrt4.dll  6.3.9600.16384
profapi.dll C:\Windows\System32\profapi.dll 6.3.9600.16384
sechost.dll C:\Windows\System32\sechost.dll 6.3.9600.16384
nsi.dll C:\Windows\System32\nsi.dll 6.3.9600.16384
Wldap32.dll C:\Windows\System32\Wldap32.dll 6.3.9600.16384
normaliz.dll    C:\Windows\System32\normaliz.dll    6.3.9600.16384
ssleay32.dll    D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\ssleay32.dll 1.0.1.6
sspicli.dll C:\Windows\System32\sspicli.dll 6.3.9600.16408
CRYPTBASE.dll   C:\Windows\System32\CRYPTBASE.dll   6.3.9600.16384
bcryptPrimitives.dll    C:\Windows\System32\bcryptPrimitives.dll    6.3.9600.16384
winsta.dll  C:\Windows\System32\winsta.dll  6.3.9600.16384
IPHLPAPI.DLL    C:\Windows\System32\IPHLPAPI.DLL    6.3.9600.16384
winnsi.dll  C:\Windows\System32\winnsi.dll  6.3.9600.16384
dhcpcsvc6.DLL   C:\Windows\System32\dhcpcsvc6.DLL   6.3.9600.16384
dhcpcsvc.dll    C:\Windows\System32\dhcpcsvc.dll    6.3.9600.16384
mswsock.dll C:\Windows\System32\mswsock.dll 6.3.9600.16384
dnsapi.dll  C:\Windows\System32\dnsapi.dll  6.3.9600.16423
rasadhlp.dll    C:\Windows\System32\rasadhlp.dll    6.3.9600.16384
NapiNSP.dll C:\Windows\System32\NapiNSP.dll 6.3.9600.16384
pnrpnsp.dll C:\Windows\System32\pnrpnsp.dll 6.3.9600.16384
nlaapi.dll  C:\Windows\System32\nlaapi.dll  6.3.9600.16384
winrnr.dll  C:\Windows\System32\winrnr.dll  6.3.9600.16384
wshbth.dll  C:\Windows\System32\wshbth.dll  6.3.9600.16384
cryptsp.dll C:\Windows\System32\cryptsp.dll 6.3.9600.16384
rsaenh.dll  C:\Windows\System32\rsaenh.dll  6.3.9600.16384
bcrypt.dll  C:\Windows\System32\bcrypt.dll  6.3.9600.16384

Call Stack:

    00000003()  Unknown
    [Frames below may be incorrect and/or missing]  
>   MyDesktop.dll!HandleModifyEvent(...) Line 159   C
    MyDesktop.dll!ProcessFSEvent(...) Line 79   C
    MyDesktop.dll!NSFileSysEventProcessor(void * lpParam=0x01adf324) Line 59    C
    MyDesktop.dll!thread_first_breath(sThrdInfo * psParam=0x009d2848) Line 1119 C
    msvcr110d.dll!_callthreadstartex() Line 354 C
    msvcr110d.dll!_threadstartex(void * ptd=0x009ff308) Line 337    C
    kernel32.dll!7790495d() Unknown
    ntdll.dll!77b498ee()    Unknown
    ntdll.dll!77b498c4()    Unknown

Upvotes: 0

Views: 1712

Answers (1)

david.pfx
david.pfx

Reputation: 10853

Within reasonable assumptions, this code cannot generate this error. The size of this array is one short, but it's still 260 in length which is plenty for the example.

An access violation of this kind is strongly suggestive of a wild store. One or more of the pointer arguments to the function has been corrupted and triggers an access violation when used.


As pointed out in a comment, access violations of the nature of "at location 0x000000nn" strongly indicate a NULL pointer dereference to a structure or class member that is nn bytes offset from the beginning of the object. Sometimes it will be a pointer that has had a small integer stored into it. Sometimes it will be a null that has been incremented. All strongly suggestive of data getting overwritten somewhere.

Upvotes: 3

Related Questions