Skip to content

Record the image type on ImageData - #341

Open
arpitjain099 wants to merge 1 commit into
NERSC:masterfrom
arpitjain099:fix/record-image-type
Open

arpitjain099 wants to merge 1 commit into
NERSC:masterfrom
arpitjain099:fix/record-image-type

Conversation

@arpitjain099

Copy link
Copy Markdown

ImageData has a type field, but nothing writes to it. Grepping ->type across src/ gives one assignment, free_ImageData setting it to NULL, and shifterimg.c working on a different struct. parse_ImageData takes type as an argument, branches on it, and never stores it.

shifter_core.c reads that field:

if (imageData->type != NULL && strcmp(imageData->type, "local") == 0 && udiConfig->allowLocalChroot == 0) {

Since the field is always NULL, the first clause short-circuits and allowLocalChroot is never consulted. Compiling the real ImageData.c and calling the function directly:

parse_ImageData(type="local") ret=0
  image.type = (NULL)
  guard would fire: NO

After the change the same call reports local and the guard fires.

The assignment leaves an existing value alone rather than replacing it, because setupLocalRootVFSConfig in the test suite passes image->type as the argument; freeing it there is a use-after-free two lines later, which AddressSanitizer flagged when I tried that first.

I could not run the CppUTest suite, this machine is macOS and the tree needs Linux headers, so the check above is a harness around the real function rather than a suite run.

ImageData carries a type field but nothing ever assigned it; the only mention
outside the struct is free_ImageData setting it to NULL. shifter_core.c reads
it to decide whether allowLocalChroot applies, and with the field always NULL
that test short-circuits, so the setting has no effect. parse_ImageData now
stores the type it was given, leaving an existing value alone since a caller
can pass image->type itself.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant