mirror of
https://github.com/zrax/pycdc.git
synced 2026-06-23 11:34:07 +00:00
Fix several undefined behavior issues identified by @nrathaus.
Fixes #147.
This commit is contained in:
parent
a9a362254e
commit
bf60a5831b
12 changed files with 152 additions and 55 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include "pyc_module.h"
|
||||
#include "data.h"
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
static void ascii_to_utf8(char** data)
|
||||
{
|
||||
|
|
@ -64,6 +65,9 @@ void PycString::load(PycData* stream, PycModule* mod)
|
|||
else
|
||||
m_length = stream->get32();
|
||||
|
||||
if (m_length < 0 || (m_length > std::numeric_limits<int>::max() - 1))
|
||||
throw std::bad_alloc();
|
||||
|
||||
if (m_length) {
|
||||
m_value = new char[m_length+1];
|
||||
stream->getBuffer(m_length, m_value);
|
||||
|
|
@ -95,6 +99,8 @@ bool PycString::isEqual(const char* str) const
|
|||
{
|
||||
if (m_value == str)
|
||||
return true;
|
||||
if (!m_value)
|
||||
return false;
|
||||
return (strcmp(m_value, str) == 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue