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

Issue in "magic" module can lead to bad results or crash #1663

Closed
plusvic opened this issue Mar 17, 2022 · 0 comments
Closed

Issue in "magic" module can lead to bad results or crash #1663

plusvic opened this issue Mar 17, 2022 · 0 comments

Comments

@plusvic
Copy link
Member

plusvic commented Mar 17, 2022

The "magic" module has an issue that may cause the type() and mime_type() functions to return wrong results. The issue is caused by the caching mechanism, which holds a pointer to a buffer that becomes invalid after the libmagic API is called by a second time.

import "magic" 

rule buggy { 
  condition:
      magic.type() contains "Mach-O" and 
      magic.mime_type() == "application/x-mach-binary" and
      magic.type() contains "Mach-O
},

In the example above, the first time that type() is called it returns a value that gets cached internally by saving the pointer returned by the magic_buffer function, which is part of the libmagic API. This buffer is valid only until the call to mime_type(). When type() is called by the second time the module doesn't call magic_buffer again, it uses the previously cached pointer which was already invalid. This causes that the second call to type() may return gibberish or even crash.

@plusvic plusvic changed the title Issue in "magic" module can lead to bad results. Issue in "magic" module can lead to bad results or crash Mar 17, 2022
plusvic added a commit that referenced this issue Mar 17, 2022
tarterp pushed a commit to mandiant/yara that referenced this issue Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant