Validate short and long names so whitespace or empty names cannot be used#6993
Merged
thebentern merged 7 commits intomeshtastic:masterfrom Jun 13, 2025
Merged
Conversation
…hort_name. Firmware should expect at least 1 non-whitespace character for both long_name and short_name. added the USERPREFS_CONFIG_DEVICE_ROLE example to userPrefs.jsonc
…an use whitespace characters. Return BAD_REQUEST error responses when validation fails and warning logs when validation rejects invalid names.
…d to match python cli command
fifieldt
approved these changes
Jun 8, 2025
Contributor
Author
|
Forgot to comment, PR for python cli made as well: |
Closed
1 task
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds validation to reject empty or whitespace-only owner and ham names and updates the userPrefs.jsonc example to include a DEVICE_ROLE.
- Added
USERPREFS_CONFIG_DEVICE_ROLEexample inuserPrefs.jsonc - Implemented whitespace/empty-string validation for
long_nameandshort_nameinAdminModule.cpp - Added similar validation for ham mode parameters in
handleSetHamMode
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| userPrefs.jsonc | Added example for USERPREFS_CONFIG_DEVICE_ROLE |
| src/modules/AdminModule.cpp | Enforced non-whitespace name validation for owner and ham modes |
Comments suppressed due to low confidence (2)
src/modules/AdminModule.cpp:158
- Add tests for owner long_name and short_name validation covering empty and whitespace-only inputs to verify the new checks.
case meshtastic_AdminMessage_set_owner_tag:
src/modules/AdminModule.cpp:1179
- Introduce tests for ham call_sign and short_name validation to ensure whitespace-only values are correctly rejected.
// Validate ham parameters before setting since this would bypass validation in the owner struct
Comment on lines
+160
to
+179
| if (*r->set_owner.long_name) { | ||
| const char *start = r->set_owner.long_name; | ||
| // Skip all whitespace (space, tab, newline, etc) | ||
| while (*start && isspace((unsigned char)*start)) | ||
| start++; | ||
| if (*start == '\0') { | ||
| LOG_WARN("Rejected long_name: must contain at least 1 non-whitespace character"); | ||
| myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); | ||
| break; | ||
| } | ||
| } | ||
| if (*r->set_owner.short_name) { | ||
| const char *start = r->set_owner.short_name; | ||
| while (*start && isspace((unsigned char)*start)) | ||
| start++; | ||
| if (*start == '\0') { | ||
| LOG_WARN("Rejected short_name: must contain at least 1 non-whitespace character"); | ||
| myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Empty owner.long_name values (first character '\0') bypass validation due to the initial if guard. Remove or adjust the if (*...) check so that empty strings are also rejected.
Suggested change
| if (*r->set_owner.long_name) { | |
| const char *start = r->set_owner.long_name; | |
| // Skip all whitespace (space, tab, newline, etc) | |
| while (*start && isspace((unsigned char)*start)) | |
| start++; | |
| if (*start == '\0') { | |
| LOG_WARN("Rejected long_name: must contain at least 1 non-whitespace character"); | |
| myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); | |
| break; | |
| } | |
| } | |
| if (*r->set_owner.short_name) { | |
| const char *start = r->set_owner.short_name; | |
| while (*start && isspace((unsigned char)*start)) | |
| start++; | |
| if (*start == '\0') { | |
| LOG_WARN("Rejected short_name: must contain at least 1 non-whitespace character"); | |
| myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); | |
| break; | |
| } | |
| const char *start = r->set_owner.long_name; | |
| // Skip all whitespace (space, tab, newline, etc) | |
| while (*start && isspace((unsigned char)*start)) | |
| start++; | |
| if (*start == '\0') { | |
| LOG_WARN("Rejected long_name: must contain at least 1 non-whitespace character"); | |
| myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); | |
| break; | |
| } | |
| const char *start = r->set_owner.short_name; | |
| while (*start && isspace((unsigned char)*start)) | |
| start++; | |
| if (*start == '\0') { | |
| LOG_WARN("Rejected short_name: must contain at least 1 non-whitespace character"); | |
| myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); | |
| break; |
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.
I saw feature request #6867 and figured this would be a good addition to the firmware and Python CLI.
I have added validation for empty and whitespace characters as short, long, and ham names. When trying to set them via the CLI, I see the following below in the serial output logs.
Should these be ERROR instead of WARN? I have also modified the Python CLI and will create a PR on that so that you get an error when trying to set blank or whitespace names.
I have also added userPrefs.jsonc USERPREFS_CONFIG_DEVICE_ROLE example addition for #6972 since I forgot to add it in my last PR.
Please let me know if there is anything that needs to be added or modified. I have no idea what I am doing with Android SDK/development, so I believe someone will need to add this validation so the app also gives an error/warning when trying to set these.
🤝 Attestations