Skip to content

Validate short and long names so whitespace or empty names cannot be used #6993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 13, 2025

Conversation

Crank-Git
Copy link
Contributor

@Crank-Git Crank-Git commented Jun 8, 2025

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.

DEBUG | 08:26:41 75 [Router] Client set owner
WARN | 08:26:41 75 [Router] Rejected long_name: must contain at least 1 non-whitespace character

DEBUG | 08:27:24 116 [Router] Client set owner
WARN | 08:27:24 116 [Router] Rejected short_name: must contain at least 1 non-whitespace character

DEBUG | 08:28:55 35 [Router] Client set owner
WARN | 08:28:55 35 [Router] Rejected ham short_name: must contain at least 1 non-whitespace character

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

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

Crank-Git added 5 commits June 8, 2025 03:32
…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.
@Crank-Git
Copy link
Contributor Author

Forgot to comment, PR for python cli made as well:
meshtastic/python#782

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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_ROLE example in userPrefs.jsonc
  • Implemented whitespace/empty-string validation for long_name and short_name in AdminModule.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;
}
Copy link
Preview

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

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

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;

Copilot uses AI. Check for mistakes.

@thebentern thebentern merged commit 8faa04a into meshtastic:master Jun 13, 2025
52 checks passed
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.

3 participants