AmendHub

Download:

jcs

/

subtext

/

amendments

/

620

signup: Error-path fixes, use strlcpy


jcs made amendment 620 9 months ago
--- signup.c Tue Dec 5 10:45:20 2023 +++ signup.c Thu Dec 11 20:50:36 2025 @@ -51,12 +51,17 @@ signup(struct session *s) session_output(s, "\r\n", 2); session_flush(s); - if (username == NULL || username[0] == '\0' || s->ending) + if (username == NULL) goto signup_done; - + if (username[0] == '\0' || s->ending) { + xfree(&username); + goto signup_done; + } + if (!user_valid_username(NULL, username, &error)) { session_printf(s, "{{B}}Error:{{/B}} %s\r\n", error); xfree(&error); + xfree(&username); continue; } @@ -72,7 +77,7 @@ signup(struct session *s) if (password == NULL || s->ending) goto signup_done; - + if (password[0] == '\0') { session_printf(s, "{{B}}Error:{{/B}} " "Password cannot be blank\r\n"); @@ -89,7 +94,7 @@ signup(struct session *s) if (password_confirm == NULL || s->ending) goto signup_done; - + if (strcmp(password_confirm, password) != 0) { session_printf(s, "{{B}}Error:{{/B}} " "Passwords do not match\r\n"); @@ -104,7 +109,7 @@ signup(struct session *s) user = xmalloczero(sizeof(struct user)); if (user == NULL) goto signup_done; - strncpy(user->username, username, sizeof(user->username)); + strlcpy(user->username, username, sizeof(user->username)); user->created_at = Time; user->is_enabled = 1; user_set_password(user, password);