@@ -291,14 +291,13 @@ static int invalid_birthday(struct tm *tm)
291291}
292292
293293static int make_user (const char * username , const char * password , const char * fullname , const char * email , const char * phone ,
294- const char * address , const char * city , const char * state , const char * zip , const char * dob , char gender )
294+ const char * address , const char * city , const char * state , const char * zip , const char * dob , const char * gender )
295295{
296- char pw_hash [61 ];
296+ char pw_hash [BCRYPT_FULL_HASH_LEN + 1 ];
297297 MYSQL * mysql = NULL ;
298298 MYSQL_STMT * stmt ;
299299 int res = -1 ;
300300 char sql [184 ];
301- char genderbuf [2 ] = { gender , '\0' }; /* We can't pass a char directly into sql_prep_bind_exec, we must pass a char* */
302301 struct tm birthday ;
303302 char types [16 ] = "sssssssssts" ;
304303
@@ -323,8 +322,8 @@ static int make_user(const char *username, const char *password, const char *ful
323322 }
324323
325324 /* Bind parameters and execute */
326- sql_fmt_autonull (types , username , pw_hash , fullname , email , phone , address , city , state , zip , dob ? & birthday : NULL , genderbuf );
327- if (sql_prep_bind_exec (stmt , sql , types , username , pw_hash , fullname , email , phone , address , city , state , zip , dob ? & birthday : NULL , genderbuf )) {
325+ sql_fmt_autonull (types , username , pw_hash , fullname , email , phone , address , city , state , zip , dob ? & birthday : NULL , gender );
326+ if (sql_prep_bind_exec (stmt , sql , types , username , pw_hash , fullname , email , phone , address , city , state , zip , dob ? & birthday : NULL , gender )) {
328327 goto cleanup ;
329328 }
330329 res = 0 ;
@@ -341,9 +340,8 @@ static int user_register(struct bbs_node *node)
341340{
342341 /* bcrypt caps password lengths at 72, so that's where that came from */
343342 char fullname [64 ], username [64 ], password [72 ], password2 [72 ];
344- char email [64 ], phone [16 ] = "" , address [64 ] = "" , city [64 ], state [32 ], zip [10 ] = "" , dob [11 ] = "" ;
343+ char email [64 ], phone [16 ] = "" , address [64 ] = "" , city [64 ], state [32 ], zip [10 ] = "" , dob [11 ] = "" , gender [ 2 ] = "" ;
345344 char how_heard [256 ] = "" ;
346- int gender = 0 ;
347345 int res ;
348346#define MAX_REG_ATTEMPTS 6
349347 int tries = MAX_REG_ATTEMPTS ;
@@ -458,12 +456,13 @@ static int user_register(struct bbs_node *node)
458456 bbs_node_unbuffer (node ); /* We need to be unbuffered for tread */
459457 if (register_gender ) {
460458 for (; tries > 0 ; tries -- ) { /* Retries here count less than retries of the main loop */
459+ int c ;
461460 NEG_RETURN (bbs_node_writef (node , "%-*s" , REG_QLEN , REG_FMT "\rGender (MFX): " )); /* Erase existing line in case we're retrying */
462- gender = bbs_node_tread (node , MIN_MS (1 ));
463- NONPOS_RETURN (gender );
464- gender = (char ) tolower (gender );
465- if (gender == 'm' || gender == 'f' || gender == 'x' ) {
466- NEG_RETURN (bbs_node_writef (node , "%c \n" , gender )); /* Print response + newline */
461+ c = bbs_node_tread (node , MIN_MS (1 ));
462+ NONPOS_RETURN (c );
463+ gender [ 0 ] = (char ) tolower (c );
464+ if (gender [ 0 ] == 'm' || gender [ 0 ] == 'f' || gender [ 0 ] == 'x' ) {
465+ NEG_RETURN (bbs_node_writef (node , "%s \n" , gender )); /* Print response + newline */
467466 break ; /* Got a valid response */
468467 }
469468 /* Invalid, try again */
@@ -497,8 +496,9 @@ static int user_register(struct bbs_node *node)
497496 bbs_auth ("New registration attempt for user %s from IP %s\n" , username , node -> ip );
498497
499498 /* How heard is logged but not passed to make_user */
500- bbs_debug (1 , "New registration attempt: name = %s, username = %s, email = %s, phone = %s, address = %s, city = %s, state = %s, zip = %s, dob = %s, gender = %c, how heard = %s\n" ,
501- fullname , username , email , S_IF (phone ), S_IF (address ), city , state , S_IF (zip ), S_IF (dob ), gender ? gender : ' ' , S_IF (how_heard ));
499+ bbs_debug (1 , "New registration attempt: "
500+ "name = '%s', username = '%s', email = '%s', phone = '%s', address = '%s', city = '%s', state = '%s', zip = '%s', dob = '%s', gender = '%s', how heard = '%s'\n" ,
501+ fullname , username , email , S_IF (phone ), S_IF (address ), city , state , S_IF (zip ), S_IF (dob ), S_IF (gender ), S_IF (how_heard ));
502502
503503#define NULL_IFEMPTY (s ) (!*s ? NULL : s)
504504
@@ -538,7 +538,7 @@ static int user_register(struct bbs_node *node)
538538 }
539539
540540 /* Actually create the user */
541- res = make_user (username , password , fullname , email , NULL_IFEMPTY (phone ), NULL_IFEMPTY (address ), city , state , NULL_IFEMPTY (zip ), NULL_IFEMPTY (dob ), ( char ) gender );
541+ res = make_user (username , password , fullname , email , NULL_IFEMPTY (phone ), NULL_IFEMPTY (address ), city , state , NULL_IFEMPTY (zip ), NULL_IFEMPTY (dob ), NULL_IFEMPTY ( gender ) );
542542
543543 if (res ) {
544544 NEG_RETURN (bbs_node_writef (node , "%s%s%s\n" , COLOR (COLOR_FAILURE ), "Your registration was rejected." , COLOR_RESET ));
@@ -547,6 +547,7 @@ static int user_register(struct bbs_node *node)
547547 }
548548 /* If user registration actually succeeded, then this function call will succeed. If not, it won't. */
549549 res = bbs_authenticate (node , username , password );
550+ bbs_memzero (password , sizeof (password )); /* No longer need the password */
550551 if (res ) {
551552 /* Something went wrong */
552553 NEG_RETURN (bbs_node_writef (node , "%s%s%s\n" , COLOR (COLOR_FAILURE ), "An error occured in processing your registration.\n" , COLOR_RESET ));
0 commit comments