From 136e03aa33d77a127e48c033e9f94a75dbc16ed5 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Fri, 4 Jul 2025 09:36:56 +0800 Subject: [PATCH] Update device ID validation rules and help description Signed-off-by: Jianhui Zhao --- src/main.c | 4 ++-- src/utils.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 2b38af2..88666ba 100644 --- a/src/main.c +++ b/src/main.c @@ -84,8 +84,8 @@ static struct option long_options[] = { static void usage(const char *prog) { fprintf(stderr, "Usage: %s [option]\n" - " -I, --id=string Set an ID for the device(Maximum 63 bytes, valid\n" - " character:letter, number, underline and short line)\n" + " -I, --id=string Set an ID for the device(Any printable character except\n" + " space is allowed, with a maximum of 32 characters)\n" " -h, --host=string Server's host or ipaddr(Default is localhost)\n" " -p, --port=number Server port(Default is 5912)\n" " -d, --description=string Add a description to the device(Maximum 126 bytes)\n" diff --git a/src/utils.c b/src/utils.c index 5a763c7..1295d43 100644 --- a/src/utils.c +++ b/src/utils.c @@ -50,8 +50,11 @@ int find_login(char *buf, int len) bool valid_id(const char *id) { + if (strlen(id) > 32) + return false; + while (*id) { - if (!isalnum(*id) && *id != '-' && *id != '_') + if (!isprint(*id) || *id == ' ') return false; id++; }