Merge pull request #460 from majestrate/master

fix bencode read crash with empty buffer
This commit is contained in:
Jeff 2019-03-28 10:34:35 -04:00 committed by GitHub
commit 5d95873e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#include <stdlib.h> // for itoa
#include <iostream>
#include <util/endian.hpp>
namespace llarp
{

View File

@ -122,6 +122,8 @@ bencode_end(llarp_buffer_t* buff)
bool
bencode_read_dict(llarp_buffer_t* buff, struct dict_reader* r)
{
if(buff->size_left() < 2) // minimum case is 'de'
return false;
llarp_buffer_t strbuf; // temporary buffer for current element
r->buffer = buff; // set up dict_reader
if(*r->buffer->cur != 'd') // ensure is a dictionary
@ -151,6 +153,8 @@ bencode_read_dict(llarp_buffer_t* buff, struct dict_reader* r)
bool
bencode_read_list(llarp_buffer_t* buff, struct list_reader* r)
{
if(buff->size_left() < 2) // minimum case is 'le'
return false;
r->buffer = buff;
if(*r->buffer->cur != 'l') // ensure is a list
{