jcs
/subtext
/amendments
/346
signup: Handle malloc and user_save failure
jcs made amendment 346 about 1 year ago
--- signup.c Sun Aug 14 12:00:00 2022
+++ signup.c Wed Mar 1 17:05:57 2023
@@ -101,12 +101,19 @@ signup(struct session *s)
break;
}
- user = xmalloczero(sizeof(struct user), "signup user");
+ user = xmalloczero(sizeof(struct user));
+ if (user == NULL)
+ goto signup_done;
strncpy(user->username, username, sizeof(user->username));
user->created_at = Time;
user->is_enabled = 1;
user_set_password(user, password);
- user_save(user);
+ if (!user_save(user)) {
+ session_logf(s, "Failed creating new user account for %s",
+ user->username);
+ xfree(&user);
+ goto signup_done;
+ }
user_cache_usernames();
session_logf(s, "New user account created for %s", user->username);