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

sc_decompress_zlib_alloc: check inputs, avoid int underflow #1907

Merged
merged 2 commits into from
Jan 30, 2020

Conversation

frankmorgner
Copy link
Member

  • turns out, you can shrink a buffer with realloc on some implementations
  • realloc is never called with 0 (which would free the data)
  • length checking is done in zlib, we just do the allocation

closes #1905

Checklist
  • Documentation is added or updated
  • New files have a LGPL 2.1 license statement
  • PKCS#11 module is tested
  • Windows minidriver is tested
  • macOS tokend is tested

- turns out, you can shrink a buffer with realloc on some implementations
- realloc is never called with 0 (which would free the data)
- length checking is done in zlib, we just do the allocation

closes OpenSC#1905
}
if(err == Z_STREAM_END) {
if (err == Z_STREAM_END) {
if (*outLen) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite this condition to if (*outLen > 0) { for readability.

src/libopensc/compression.c Show resolved Hide resolved
@frankmorgner
Copy link
Member Author

I think I'll leave it with this simple fix.

If someone wants to rewrite this to something more sophisticated, please make a pull request.

@frankmorgner frankmorgner merged commit a501c0d into OpenSC:master Jan 30, 2020
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

Successfully merging this pull request may close these issues.

Possible problems with sc_decompress_zlib_alloc()
2 participants