Skip to content
Snippets Groups Projects
  1. Sep 21, 2017
    • Damien George's avatar
      77e1da40
    • Damien George's avatar
      980b3317
    • Damien George's avatar
      py/vstr: Raise a RuntimeError if fixed vstr buffer overflows. · ede8a023
      Damien George authored
      Current users of fixed vstr buffers (building file paths) assume that there
      is no overflow and do not check for overflow after building the vstr.  This
      has the potential to lead to NULL pointer dereferences
      (when vstr_null_terminated_str returns NULL because it can't allocate RAM
      for the terminating byte) and stat'ing and loading invalid path names (due
      to the path being truncated).  The safest and simplest thing to do in these
      cases is just raise an exception if a write goes beyond the end of a fixed
      vstr buffer, which is what this patch does.  It also simplifies the vstr
      code.
      ede8a023
    • Damien George's avatar
      py/stream: Remove unnecessary checks for NULL return from vstr_add_len. · 7885a425
      Damien George authored
      The vstr argument to the calls to vstr_add_len are dynamically allocated
      (ie fixed_buf=false) and so vstr_add_len will never return NULL.  So
      there's no need to check for it.  Any out-of-memory errors are raised by
      the call to m_renew in vstr_ensure_extra.
      7885a425
    • Damien George's avatar
      py/objexcept: Prevent infinite recursion when allocating exceptions. · 96fd80db
      Damien George authored
      The aim of this patch is to rewrite the functions that create exception
      instances (mp_obj_exception_make_new and mp_obj_new_exception_msg_varg) so
      that they do not call any functions that may raise an exception.  Otherwise
      it's possible to create infinite recursion with an exception being raised
      while trying to create an exception object.
      
      The two main things that are done to accomplish this are:
      1. Change mp_obj_new_exception_msg_varg to just format the string, then
         call mp_obj_exception_make_new to actually create the exception object.
      2. In mp_obj_exception_make_new and mp_obj_new_exception_msg_varg try to
         allocate all memory first using functions that don't raise exceptions
         If any of the memory allocations fail (return NULL) then degrade
         gracefully by trying other options for memory allocation, eg using the
         emergency exception buffer.
      3. Use a custom printer backend to conservatively format strings: if it
         can't allocate memory then it just truncates the string.
      
      As part of this rewrite, raising an exception without a message, like
      KeyError(123), will now use the emergency buffer to store the arg and
      traceback data if there is no heap memory available.
      
      Memory use with this patch is unchanged.  Code size is increased by:
      
         bare-arm:  +136
      minimal x86:  +124
         unix x64:   +72
      unix nanbox:   +96
            stm32:   +88
          esp8266:   +92
           cc3200:   +80
      96fd80db
  2. Sep 20, 2017
  3. Sep 19, 2017
  4. Sep 18, 2017
  5. Sep 17, 2017
  6. Sep 16, 2017
  7. Sep 13, 2017
  8. Sep 12, 2017
  9. Sep 10, 2017
  10. Sep 09, 2017
  11. Sep 08, 2017
  12. Sep 07, 2017
Loading