Skip to content

survive_default_devices: Fix lighthousedb.json failed to parse JSON #361

Open
Acridine wants to merge 2 commits into
collabora:masterfrom
Acridine:fix_lighthousedb_loading
Open

survive_default_devices: Fix lighthousedb.json failed to parse JSON #361
Acridine wants to merge 2 commits into
collabora:masterfrom
Acridine:fix_lighthousedb_loading

Conversation

@Acridine

@Acridine Acridine commented May 8, 2026

Copy link
Copy Markdown

This fixes issue #359, where the parsing of a lighthousedb.json generated with SteamVR fails.

Root Cause

Missing null-termination ('\0') and unchecked partial fread() results.

Changes

In survive_default_devices.c:

  • added '\0' terminator to the loaded file buffer
  • validated that fread() reads the full file before parsing.

@Acridine Acridine changed the title Fixes #359 survive_default_devices: Fix lighthousedb.json failed to parse JSON May 8, 2026

@bl4ckb0ne bl4ckb0ne left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of this issue, and apologies for not answering to your issue sooner

char *ct0conf = (char *)malloc(len);
size_t read = fread(ct0conf, 1, len, fp);
survive_load_steamvr_lighthousedb(ctx, ct0conf, len);
char *ct0conf = malloc(len + 1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer calloc to allocate memory, it also 0's the allocation to get no surprises. Plus you get the trailing \0 for free.

survive_load_steamvr_lighthousedb(ctx, ct0conf, len);
char *ct0conf = malloc(len + 1);
size_t read = fread(ct0conf, 1, len, fp);
if (read != len) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a call to ferror or at least indicate that the read failed.

Comment on lines 627 to 628
free(ct0conf);
fclose(fp);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now leaking on the normal path, those should be called after survive_load_steamvr_lighthousedb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants