Skip to content

Access Violation in SoapySDRArgInfo #447

Open
@VE3NEA

Description

Problem Description

The C wrapper around SoapySDR::ArgInfo looks like this:

static inline SoapySDRArgInfo toArgInfo(const SoapySDR::ArgInfo &info)
{
    SoapySDRArgInfo out;
    std::memset(&out, 0, sizeof(out));
    try
    {
      ...
        out.optionNames = toStrArray(info.optionNames, &out.numOptions);
        // do options after optionNames so correct numOptions is reported if no optionNames
        out.options = toStrArray(info.options, &out.numOptions);

When info.options has elements but info.optionNames doesn't, out.optionNames is assigned a pointer to a zero-length memory. The calling code has no way to know that, when it tries to read numOptions entries from that memory, an AV exception is fired.

Proposed Fix

Change toStrArray to return NULL when strs has no entries

static inline char **toStrArray(const std::vector<std::string> &strs, size_t *length)
{
  if (strs.size() == 0) return NULL;
  ...

and make a corresponding change inSoapySDRStrings_clear:

void SoapySDRStrings_clear(char ***elems, const size_t length)
{
  if (*elems == NULL) return;
  ...

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions