Skip to content

Bug relating to autosort in PayloadGenerator #10

@dok852

Description

@dok852

There's a mistake in the autosorting logic inside PayloadGenerator, as a consequence payload generation will often fail, raising a ValueError: Unknown error. Missing bytes on line 166 or an IndexError: list index out of range on line 180 of core.py.

A proof of concept crash:

from libformatstr import *

f = FormatStr()
f[0xdddddd05] = 0xcccccccc
payload = f.payload(6)

This is as a result of the if statement on line 145 of core.py being the wrong way round. At the moment the default value of autosort is True, and the if statement is:

if autosort:
    self.addrs = list(mem.keys())  # addresses of each byte to set
else:
    self.addrs = list(sorted(mem.keys()))

Which means the keys aren't sorted by default, causing various problems.
To rectify this the lines can simply be switched around like so:

if autosort:
    self.addrs = list(sorted(mem.keys()))  # addresses of each byte to set
else:
    self.addrs = list(mem.keys())

This only appears to be a problem in this git repository. The versions in pip don't have the autosort property so keys are always sorted and this problem doesn't exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions