bip39: fail if the callers requested language is not found
What changed, and why it matters
This commit fixes a behavior in the BIP39 (mnemonic seed phrase) code where, if a caller asked for a language that wasn't supported, the library would quietly give them the English wordlist instead of reporting an error. The patch makes the function return an error when the requested language is missing, and only default to English when no language is explicitly requested. This prevents silent mismatches between what the caller expects and what they get.
Review downstream callers of `bip39_get_wordlist()` to ensure they handle `WALLY_EINVAL` correctly and are not passing invalid language strings that previously worked due to silent fallback. Consider adding tests for unknown language handling.
Security signals we found
Silent fallback to default language could cause language/cross-check mismatches
Behavioral change from permissive fallback to explicit failure
Potential downstream impact if callers previously passed invalid language strings and relied on English fallback
No explicit security framing in commit message or diff
Evidence from the diff
In bip39_get_wordlist(), the previous code unconditionally set *output = &en_words before checking the requested language, meaning any unknown lang value would silently fall back to English. The patch initializes *output to NULL, only assigns English when lang is NULL, and returns WALLY_EINVAL if a non-NULL language is not found in the lookup table. This is a correctness fix that may have security implications for downstream code that relies on language-specific wordlists.
Changed components
src/bip39.cbip39_get_wordlist() functionInspect captured patch +8 / −4
### src/bip39.c
@@ -46,18 +46,22 @@ int bip39_get_wordlist(const char *lang, struct words **output)
{
size_t i;
+ if (output)
+ *output = NULL;
+
if (!output)
return WALLY_EINVAL;
- *output = (struct words *)&en_words; /* Fallback to English if not found */
-
- if (lang)
+ if (!lang)
+ *output = (struct words *)&en_words; /* Use English if not given */
+ else {
for (i = 0; i < NUM_ELEMS(lookup); ++i)
if (!strcmp(lang, lookup[i].name)) {
*output = (struct words *)lookup[i].words;
break;
}
- return WALLY_OK;
+ }
+ return *output ? WALLY_OK : WALLY_EINVAL;
}
const char *bip39_get_word_by_index(const struct words *w, size_t idx)Why this scored 51/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.