Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown when parsing the header file in Microsoft SDK #46

Open
ShadowLL opened this issue Apr 9, 2020 · 3 comments
Open

Exception thrown when parsing the header file in Microsoft SDK #46

ShadowLL opened this issue Apr 9, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@ShadowLL
Copy link

ShadowLL commented Apr 9, 2020

typedef enum _WSACOMPLETIONTYPE {
    NSP_NOTIFY_IMMEDIATELY = 0,
    NSP_NOTIFY_HWND,
    NSP_NOTIFY_EVENT,
    NSP_NOTIFY_PORT,
    NSP_NOTIFY_APC,
} WSACOMPLETIONTYPE, *PWSACOMPLETIONTYPE, FAR * LPWSACOMPLETIONTYPE;

This is detailed exception information:

Connected to pydev debugger (build 192.6262.63)
Traceback (most recent call last):
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 2913, in __init__
    self._evaluate_stack()
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3343, in _evaluate_stack
    self._parse_enum()
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3536, in _parse_enum
    self._next_token_must_be(";")
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3113, in _next_token_must_be
    raise self._parse_error((tok,), "' or '".join(tokenTypes))
CppHeaderParser.CppHeaderParser.CppParseError: unexpected ',', expected ';'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 2060, in <module>
    main()
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/fuzz/app/pycharm-2019.2.1/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/fuzz/workspace/xfuzz/database/src_code_analysis/analysis.py", line 3, in <module>
    header = CppHeaderParser.CppHeader('/home/fuzz/workspace/xfuzz/database/windos_sdk_hfs/Include/WinSock2.h')
  File "/home/fuzz/.virtualenvs/pypy_xfuzz/site-packages/CppHeaderParser/CppHeaderParser.py", line 3048, in __init__
    CppParseError(msg), e,
  File "<string>", line 1, in raise_exc
CppHeaderParser.CppHeaderParser.CppParseError: Not able to parse /home/fuzz/workspace/xfuzz/database/windos_sdk_hfs/Include/WinSock2.h on line 1074 evaluating ',': unexpected ',', expected ';'
Error around: typedef enum _WSACOMPLETIONTYPE
@virtuald
Copy link
Member

virtuald commented Apr 9, 2020

Definitely a bug. I don't really have an interest in fixing this myself (lots of stuff going on), but I can provide guidance for debugging/fixing this if you would like to fix it and make a PR.

In particular, I find that setting the environment variable CPPHEADERPARSER_DEBUG=1 is really useful for figuring out what the parser is doing.

I imagine that this isn't the only piece in the SDK that would cause problems. Might try just commenting out that enum and see what else breaks.

@virtuald virtuald added the bug Something isn't working label Apr 9, 2020
@liuyongbao1982
Copy link

The following code has the same parsing error: evaluating '': unexpected '', expected ';'
struct AudioPortCapability {
enum AudioFormat* formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */
};


After I modified the following code, the program can run normally:
def _parse_enum(self):
......
# TODO: nested_name_specifier
name = ""
if nametok.type == "NAME":
name = nametok.value
debug_print("enum name is '%s'", name)
tok = self.lex.token()
#MODIFED:
if tok.value == "*":
name = name + ' *'
tok = self.lex.token()
else:
debug_print("anonymous enum")
tok = nametok

@auscompgeek
Copy link
Member

@liuyongbao1982 That looks like a different parse error to me. If you open a PR though with your change and a test, we'd be happy to take your change, since that's also a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants