Skip to content

unsigned rc makes every send-error check in the list handlers dead code #267

Description

@mgrossmann

Found while working on #249, deliberately left alone there to keep that PR to
one subject.

The defect

datasetListHandler() and memberListHandler() both declare:

unsigned	rc		= 0;

and then check every write like this:

if ((rc = http_printf(session->httpc, "...")) < 0) goto quit;

rc is unsigned, so rc < 0 is never true. Every one of those checks is dead
code
— a failed http_printf() or http_resp() is assigned and discarded,
and the handler keeps writing to a socket that is already gone. A client that
disconnects mid-listing has the whole remaining directory written after it.

It compiles clean because -Wall does not include -Wtype-limits
(that is -Wextra).

Where it is

  • src/dsapi.cdatasetListHandler()
  • src/dsapi.cmemberListHandler()

Worth grepping the other handlers in the same pass: the pattern is copied
around, and anywhere rc is unsigned the same checks are inert.

Note on the fix

Changing the declaration to int is a one-word edit but it is not a no-op —
it activates every one of those goto quit paths for the first time. The
cleanup at quit: needs a read in that light before flipping it.

For what it is worth, an early exit there appears harmless today: handle_request()
returns the handler's rc to mvsmf.c, which assigns it to irc and returns 0
regardless, so nothing tries to send a 500 on top of a partly written body. The
headers_sent guard in router.c:157 only covers the abend path.

member_scan() (added in #265) is currently the only place in the member list
where a write failure is actually detected, because it returns int.

Metadata

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