Repository navigation
Config: Fix crash loading a config without a mouse_type key - #7924
Merged
OBattler merged 1 commit intoSep 11, 2026
Merged
Conversation
The tablet migration added in 10cdcda passes the string returned by ini_section_get_string(cat, "mouse_type", NULL) straight to tablet_get_from_internal_name(), outside the NULL check two lines above it. ini_section_get_string() returns the default when the key is missing and also when the whole section is missing, so a config file without a mouse_type line reaches the strcmp() in that lookup with a NULL pointer and 86Box segfaults before the window appears. Fold the migration into the existing non-NULL branch, which leaves it unchanged for every config that does have the key.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
86Box segfaults during startup when it loads a config file that has no
mouse_typeline under[Input devices], or no[Input devices]section at all. There is no message, the main window never appears. 86Box always writesmouse_typewhen it saves (src/config.c:3392), so configs it wrote itself are fine. What hits this is a hand written or hand trimmed config, one produced by another tool, or one truncated by an interrupted save.The key is read with a NULL default at
src/config.c:783. The mouse lookup right below it is guarded, and so is thetablet_typelookup atsrc/config.c:793, but the migration atsrc/config.c:790passes the same pointer along unguarded:ini_section_get_string()returns itsdefargument both when the section is missing (src/utils/ini.c:903) and when the key is missing (src/utils/ini.c:907), sopis NULL in either case.tablet_get_from_internal_name()then callsstrcmp()on it atsrc/device/mouse.c:736. The&&evaluates the tablet lookup first, so themouse_type == 0test never gets the chance to short circuit it.This patch moves the migration inside the existing
if (p != NULL)branch. Configs that do have the key behave exactly as before, including writingtablet_typebefore the read two lines further down picks it up.The migration was added in 10cdcda "Handle migrations" and touched again in 65accb5 "Fix migration", which corrected the value passed to
ini_section_set_string()but not the guard.I checked it with a small driver built against the real parser,
src/utils/ini.cplus stubs forplat_fopen,rom_fopenandstricmp, running the block above on a config containing only a[Machine]section. Before the change it printssection = 0x0,mouse_type = 0x0,calling tablet_get_from_internal_name(0x0)and exits 139. After the change it printssurvived, mouse_type = 0and exits 0. A second driver whose[Input devices]section names a tablet device inmouse_typeprints the same migratedtablet_typeboth before and after, so the migration itself is unchanged.clang -fsyntax-only -Wall -Wextra -std=gnu11onsrc/config.creports the same 238 warnings before and after, none of them on the touched lines, and the hunk is unchanged by clang-format with the repository.clang-format.Checklist
References