AmendHub

Download:

jcs

/

subtext

/

amendments

/

226

*: Add malloc annotations


jcs made amendment 226 about 1 year ago
--- ansi.c Mon Jun 27 09:07:22 2022 +++ ansi.c Sun Jul 31 18:09:04 2022 @@ -234,7 +234,7 @@ ansi_strip(char *inp, char **outp) short in_csi; if (outp) - *outp = xmalloc(ilen + 1); + *outp = xmalloc(ilen + 1, "ansi_strip"); for (n = 0, in_csi = 0; n < ilen; ) { if (in_csi) { --- board.c Wed Jul 20 09:32:20 2022 +++ board.c Sun Jul 31 18:15:08 2022 @@ -295,7 +295,8 @@ board_list_posts(struct session *s, struct board *boar size = bile_read_alloc(board->bile, BOARD_POST_RTYPE, post_ids[n], &data); bile_unmarshall_object(board->bile, board_post_object_fields, - nboard_post_object_fields, data, size, &post, false); + nboard_post_object_fields, data, size, &post, sizeof(post), + false); xfree(&data); if (post.thread_id != thread.thread_id) { @@ -307,7 +308,8 @@ board_list_posts(struct session *s, struct board *boar size = bile_read_alloc(board->bile, BOARD_THREAD_RTYPE, post.thread_id, &data); bile_unmarshall_object(board->bile, board_thread_object_fields, - nboard_thread_object_fields, data, size, &thread, true); + nboard_thread_object_fields, data, size, &thread, + sizeof(thread), true); xfree(&data); for (j = 0; j < nitems(indent_parent_ids); j++) @@ -383,12 +385,13 @@ board_compose(struct session *s, struct board *board, } if (initial_body) - post.body = xstrdup(initial_body); + post.body = xstrdup(initial_body, "board_compose body"); if (thread) { post.thread_id = thread->thread_id; post.parent_post_id = parent_post->id; } else - thread = xmalloczero(sizeof(struct board_thread)); + thread = xmalloczero(sizeof(struct board_thread), + "board_compose thread"); post.sender_user_id = s->user->id; @@ -404,7 +407,8 @@ post_compose_start: session_flush(s); } else { if (initial_subject && !thread->subject) - thread->subject = xstrdup(initial_subject); + thread->subject = xstrdup(initial_subject, + "board_compose subject"); for (;;) { session_printf(s, "{{B}}Subject:{{/B}} "); @@ -553,7 +557,7 @@ board_post_read(struct session *s, struct board *board panic("failed fetching message %ld: %d", id, bile_error(board->bile)); bile_unmarshall_object(board->bile, board_post_object_fields, - nboard_post_object_fields, data, size, &post, true); + nboard_post_object_fields, data, size, &post, sizeof(post), true); xfree(&data); size = bile_read_alloc(board->bile, BOARD_THREAD_RTYPE, @@ -562,10 +566,11 @@ board_post_read(struct session *s, struct board *board panic("failed fetching thread %ld: %d", post.thread_id, bile_error(board->bile)); bile_unmarshall_object(board->bile, board_thread_object_fields, - nboard_thread_object_fields, data, size, &thread, true); + nboard_thread_object_fields, data, size, &thread, sizeof(thread), + true); xfree(&data); - dopts = xmalloc(sizeof(opts)); + dopts = xmalloc(sizeof(opts), "board_post_read opts"); memcpy(dopts, opts, sizeof(opts)); if (!(s->user && (s->user->is_sysop || s->user->id == post.sender_user_id))) { @@ -685,15 +690,19 @@ board_find_post_ids(struct board *board, size_t *npost if (nthreads == 0) return 0; - thread_map = xcalloc(sizeof(struct board_thread_map), nthreads); + thread_map = xcalloc(sizeof(struct board_thread_map), nthreads, + "board_find_post_ids thread_map"); for (n = 0; o = bile_get_nth_of_type(board->bile, n, BOARD_THREAD_RTYPE); n++) { - if (n >= nthreads) + if (n >= nthreads) { + xfree(&o); break; + } bile_read_alloc(board->bile, BOARD_THREAD_RTYPE, o->id, &data); bile_unmarshall_object(board->bile, board_thread_object_fields, - nboard_thread_object_fields, data, o->size, &thread, false); + nboard_thread_object_fields, data, o->size, &thread, + sizeof(thread), false); xfree(&data); xfree(&o); @@ -723,7 +732,8 @@ board_find_post_ids(struct board *board, size_t *npost size = bile_read_alloc(board->bile, BOARD_THREAD_RTYPE, thread_map[j].id, &data); bile_unmarshall_object(board->bile, board_thread_object_fields, - nboard_thread_object_fields, data, size, &thread, true); + nboard_thread_object_fields, data, size, &thread, sizeof(thread), + true); xfree(&data); for (i = 0; i < thread.nposts; i++) { @@ -864,9 +874,10 @@ board_delete_post(struct session *s, struct board *boa if (!childs) { /* just zap this off the end of the tree */ - new_post_ids = xcalloc(thread->nposts - 1, sizeof(unsigned long)); + new_post_ids = xcalloc(thread->nposts - 1, sizeof(unsigned long), + "board_delete_post new_post_ids"); new_parent_post_ids = xcalloc(thread->nposts - 1, - sizeof(unsigned long)); + sizeof(unsigned long), "board_delete_post new_parent_post_ids"); for (n = 0, nn = 0; n < thread->nposts; n++) { if (thread->post_ids[n] == post->id) @@ -917,7 +928,7 @@ board_delete_post(struct session *s, struct board *boa xfree(&post->body); snprintf(del, sizeof(del), "[ Post deleted by %s ]", s->user ? s->user->username : "unknown"); - post->body = xstrdup(del); + post->body = xstrdup(del, "board_delete_post deleted body"); post->body_size = strlen(post->body) + 1; ret = bile_marshall_object(board->bile, board_post_object_fields, --- console.c Wed Jul 20 12:56:21 2022 +++ console.c Sun Jul 31 21:52:00 2022 @@ -67,7 +67,7 @@ console_init(void) Rect bounds; short width, height; - console = xmalloczero(sizeof(struct console)); + console = xmalloczero(sizeof(struct console), "console_init"); console->session = session_create("console", "console", &console_node_funcs); @@ -101,7 +101,7 @@ console_init(void) if (!console->win) panic("Can't create window"); - focusable = xmalloczero(sizeof(struct focusable)); + focusable = xmalloczero(sizeof(struct focusable), "console focusable"); focusable->win = console->win; focusable->cookie = console; focusable->update = console_update; --- db.c Wed Jul 20 09:34:13 2022 +++ db.c Sun Jul 31 21:57:57 2022 @@ -197,7 +197,7 @@ db_init(Str255 path, short vrefnum, struct bile *bile) WriteResource(lastfileh); DetachResource(lastfileh); - tdb = xmalloczero(sizeof(struct db)); + tdb = xmalloczero(sizeof(struct db), "db_init db"); tdb->bile = bile; if (db_migrate(tdb, was_new) != 0) { @@ -268,7 +268,7 @@ db_migrate(struct db *tdb, short is_new) db_config_save(tdb); /* create a default sysop user */ - user = xmalloczero(sizeof(struct user)); + user = xmalloczero(sizeof(struct user), "db_migrate user"); strncpy(user->username, "sysop", sizeof(user->username)); user->created_at = Time; user->is_enabled = DB_TRUE; @@ -454,7 +454,8 @@ db_cache_boards(struct db *tdb) &ids); if (!tdb->nboards) return; - tdb->boards = xcalloc(tdb->nboards, sizeof(struct board)); + tdb->boards = xcalloc(tdb->nboards, sizeof(struct board), + "db_cache_boards"); /* * Read ids first so we have a consistent order, then try to open or @@ -469,7 +470,7 @@ db_cache_boards(struct db *tdb) &data); bile_unmarshall_object(tdb->bile, board_object_fields, nboard_object_fields, data, size, (char *)(&tdb->boards[n]), - true); + sizeof(struct board), true); xfree(&data); } @@ -573,7 +574,8 @@ db_cache_folders(struct db *tdb) &ids); if (!tdb->nfolders) return; - tdb->folders = xcalloc(tdb->nfolders, sizeof(struct folder)); + tdb->folders = xcalloc(tdb->nfolders, sizeof(struct folder), + "db_cache_folders"); /* * Read ids first so we have a consistent order, then try to open or @@ -587,7 +589,7 @@ db_cache_folders(struct db *tdb) size = bile_read_alloc(tdb->bile, DB_FOLDER_RTYPE, obj->id, &data); bile_unmarshall_object(tdb->bile, folder_object_fields, nfolder_object_fields, data, size, (char *)(&tdb->folders[n]), - true); + sizeof(struct folder), true); xfree(&data); } --- folder.c Wed Jul 20 22:18:54 2022 +++ folder.c Sun Jul 31 21:23:06 2022 @@ -326,7 +326,8 @@ folder_list_files(struct session *s, struct folder *fo size = bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, file_ids[off + n], &data); bile_unmarshall_object(folder->bile, folder_file_object_fields, - nfolder_file_object_fields, data, size, &file, false); + nfolder_file_object_fields, data, size, &file, sizeof(file), + false); xfree(&data); strftime(time, sizeof(time), "%Y-%m-%d", localtime(&file.time)); @@ -379,7 +380,7 @@ folder_upload(struct session *s, struct folder *folder session_flush(s); session_pause_return(s, 0, "when you are ready..."); - upload_path = xmalloc(FILENAME_MAX); + upload_path = xmalloc(FILENAME_MAX, "folder_upload path"); snprintf(upload_path, FILENAME_MAX, "%s:upload-%08lx%08lx", folder->path, xorshift32(), xorshift32()); @@ -462,7 +463,7 @@ folder_upload(struct session *s, struct folder *folder session_printf(s, "Calculating SHA1 checksum of uploaded file..."); session_flush(s); SHA1Init(&sha1); - data = xmalloc(1024); + data = xmalloc(1024, "folder_upload data"); fp = fopen(upload_path, "rb"); while (fp && !feof(fp)) { size = fread(data, 1024, 1, fp); @@ -674,10 +675,10 @@ folder_file_view(struct session *s, struct folder *fol panic("failed fetching message %ld: %d", id, bile_error(folder->bile)); bile_unmarshall_object(folder->bile, folder_file_object_fields, - nfolder_file_object_fields, data, size, &file, true); + nfolder_file_object_fields, data, size, &file, sizeof(file), true); xfree(&data); - dopts = xmalloc(sizeof(opts)); + dopts = xmalloc(sizeof(opts), "folder_file_view opts"); memcpy(dopts, opts, sizeof(opts)); if (!(s->user && (s->user->is_sysop || s->user->id == file.uploader_user_id))) { @@ -722,7 +723,7 @@ folder_file_view(struct session *s, struct folder *fol switch (c) { case 'd': - path = xmalloc(FILENAME_MAX); + path = xmalloc(FILENAME_MAX, "folder_file_view filename"); snprintf(path, FILENAME_MAX, "%s:%s", folder->path, file.filename); fp = fopen(path, "rb"); @@ -857,7 +858,8 @@ folder_find_file_ids(struct folder *folder, size_t *nf if (*nfile_ids == 0) return 0; - name_map = xcalloc(*nfile_ids, sizeof(struct file_name_map)); + name_map = xcalloc(*nfile_ids, sizeof(struct file_name_map), + "folder_find_file_ids"); for (n = 0; o = bile_get_nth_of_type(folder->bile, n, FOLDER_FILE_RTYPE); n++) { @@ -865,7 +867,8 @@ folder_find_file_ids(struct folder *folder, size_t *nf break; bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, o->id, &data); bile_unmarshall_object(folder->bile, folder_file_object_fields, - nfolder_file_object_fields, data, o->size, &file, false); + nfolder_file_object_fields, data, o->size, &file, sizeof(file), + false); xfree(&data); xfree(&o); @@ -886,7 +889,7 @@ folder_find_file_ids(struct folder *folder, size_t *nf } } - *file_ids = xcalloc(sizeof(long), *nfile_ids); + *file_ids = xcalloc(sizeof(long), *nfile_ids, "folder_find_file_ids"); for (i = 0; i < *nfile_ids; i++) (*file_ids)[i] = name_map[i].id; @@ -926,7 +929,7 @@ folder_file_save(struct folder *folder, struct folder_ bile_flush(folder->bile, true); - new_name = xmalloc(FILENAME_MAX); + new_name = xmalloc(FILENAME_MAX, "folder_file_save"); snprintf(new_name, FILENAME_MAX, "%s:%s", folder->path, file->filename); CtoPstr(temp_path); @@ -956,7 +959,7 @@ folder_delete_file(struct session *s, struct folder *f bile_delete(folder->bile, FOLDER_FILE_RTYPE, file->id); bile_flush(folder->bile, true); - path = xmalloc(FILENAME_MAX); + path = xmalloc(FILENAME_MAX, "folder_delete_file"); snprintf(path, FILENAME_MAX, "%s:%s", folder->path, file->filename); CtoPstr(path); ret = FSDelete(path, 0); @@ -985,13 +988,14 @@ folder_file_valid_filename(struct session *session, char c; if (file->filename[0] == '\0') { - *error = xstrdup("filename cannot be empty"); + *error = xstrdup("filename cannot be empty", + "folder_file_valid_filename"); return false; } len = strlen(file->filename); if (len > FOLDER_FILE_FILENAME_LENGTH) { - *error = xmalloc(61); + *error = xmalloc(61, "folder_file_valid_filename"); snprintf(*error, 60, "filename cannot be more than %d characters", FOLDER_FILE_FILENAME_LENGTH); return false; @@ -1001,19 +1005,21 @@ folder_file_valid_filename(struct session *session, c = file->filename[n]; if (n == 0 && c == '.') { - *error = xstrdup("filename cannot start with a dot"); + *error = xstrdup("filename cannot start with a dot", + "folder_file_valid_filename"); return false; } if (n == len - 1 && c == ' ') { - *error = xstrdup("filename cannot end with a space"); + *error = xstrdup("filename cannot end with a space", + "folder_file_valid_filename"); return false; } if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || c == '-' || c == '+' || c == '*' || c == ' ' || c == '.' || c == ',')) { - *error = xmalloc(61); + *error = xmalloc(61, "folder_file_valid_filename"); snprintf(*error, 60, "filename cannot contain '%c' character", c); return false; @@ -1029,12 +1035,14 @@ folder_file_valid_filename(struct session *session, bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, o->id, &data); bile_unmarshall_object(folder->bile, folder_file_object_fields, - nfolder_file_object_fields, data, o->size, &tfile, false); + nfolder_file_object_fields, data, o->size, &tfile, sizeof(tfile), + false); xfree(&data); xfree(&o); if (strcasecmp(file->filename, tfile.filename) == 0) { - *error = xstrdup("filename is already taken"); + *error = xstrdup("filename is already taken", + "folder_file_valid_filename"); return false; } } --- logger.c Fri Jun 24 16:38:46 2022 +++ logger.c Sun Jul 31 23:04:19 2022 @@ -39,7 +39,7 @@ logger_init(void) Rect bounds = { 0 }; short padding = 5; - logger = xmalloczero(sizeof(struct logger)); + logger = xmalloczero(sizeof(struct logger), "logger"); bounds.left = padding; bounds.top = ((screenBits.bounds.bottom - @@ -63,7 +63,7 @@ logger_init(void) bounds.top = bounds.left = 0; logger_layout(logger, true, &bounds); - focusable = xmalloczero(sizeof(struct focusable)); + focusable = xmalloczero(sizeof(struct focusable), "logger focusable"); focusable->win = logger->win; focusable->cookie = logger; focusable->mouse_down = logger_mouse_down; @@ -82,7 +82,7 @@ void logger_layout(struct logger *logger, bool init, Rect *init_bounds) { Rect bounds, inset_bounds, win_bounds; - + if (init) win_bounds = *init_bounds; else @@ -141,7 +141,7 @@ logger_update(struct focusable *focusable, EventRecord GrafPtr old_port; Rect r; short what = -1; - + GetPort(&old_port); SetPort(logger->win); --- mail.c Wed Jul 20 09:37:20 2022 +++ mail.c Sun Jul 31 21:28:31 2022 @@ -249,11 +249,11 @@ mail_compose(struct session *s, char *initial_to, char char c; if (initial_to) - to_username = xstrdup(initial_to); + to_username = xstrdup(initial_to, "mail_compose"); if (initial_subject) - msg.subject = xstrdup(initial_subject); + msg.subject = xstrdup(initial_subject, "mail_compose"); if (initial_body) - msg.body = xstrdup(initial_body); + msg.body = xstrdup(initial_body, "mail_compose"); session_printf(s, "{{B}}Compose New Private Mail{{/B}}\r\n"); session_printf(s, "{{B}}From: {{/B}} %s\r\n", s->user->username); @@ -420,7 +420,7 @@ mail_list(struct session *s, size_t nmail_ids, unsigne if (size == 0) break; bile_unmarshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), data, size, &msg, true); + nitems(mail_object_fields), data, size, &msg, sizeof(msg), true); xfree(&data); user = user_find_username(msg.sender_user_id); @@ -472,7 +472,7 @@ mail_read(struct session *s, unsigned long id, short i } bile_unmarshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), data, size, &msg, true); + nitems(mail_object_fields), data, size, &msg, sizeof(msg), true); xfree(&data); sender = user_find_username(msg.sender_user_id); @@ -513,7 +513,8 @@ mail_read(struct session *s, unsigned long id, short i if (!sender) break; - reply_subject = xmalloc(strlen(msg.subject) + 5); + reply_subject = xmalloc(strlen(msg.subject) + 5, + "mail_read subject"); if (strncmp(msg.subject, "Re:", 3) == 0) strlcpy(reply_subject, msg.subject, strlen(msg.subject) + 1); @@ -616,7 +617,7 @@ mail_find_ids_for_user(struct user *user, size_t *nmai mail_ids_size = sizeof(long) * 16; if (mail_ids != NULL) - *mail_ids = xmalloc(mail_ids_size); + *mail_ids = xmalloc(mail_ids_size, "mail_find_ids_for_user ids"); if (nmail_ids != NULL) *nmail_ids = 0; @@ -634,7 +635,7 @@ mail_find_ids_for_user(struct user *user, size_t *nmai if (only_unread) { size = bile_read_alloc(db->bile, DB_MESSAGE_RTYPE, id, &data); bile_unmarshall_object(db->bile, mail_object_fields, - nmail_object_fields, data, size, &msg, false); + nmail_object_fields, data, size, &msg, sizeof(msg), false); read = msg.read; if (read) continue; --- main.c Thu Jul 21 08:47:03 2022 +++ main.c Sat Jul 30 22:37:11 2022 @@ -121,7 +121,9 @@ main(void) SystemTask(); if (!GetNextEvent(everyEvent, &event)) { +#ifdef MALLOC_DEBUG xfree_verify(); +#endif blanker_idle(); continue; } @@ -259,7 +261,7 @@ handle_menu(long menu_id) case APPLE_MENU_ABOUT_ID: { char *vers_s; - vers_s = xmalloc(100); + vers_s = xmalloc(100, "vers_s"); sprintf(vers_s, "%s %s", PROGRAM_NAME, get_version(true)); note("%s", vers_s); xfree(&vers_s); @@ -278,22 +280,26 @@ handle_menu(long menu_id) ret = true; quit = true; - /* - * nfocusables and focusables array will probably be modified - * as each focusable quits - */ - tfocusables = xmalloc(sizeof(Ptr) * tnfocusables); - memcpy(tfocusables, focusables, sizeof(Ptr) * tnfocusables); + if (nfocusables) { + /* + * nfocusables and focusables array will probably be + * modified as each focusable quits + */ + tfocusables = xcalloc(sizeof(Ptr), tnfocusables, + "focusables quit"); + memcpy(tfocusables, focusables, + sizeof(Ptr) * tnfocusables); - for (n = 0; n < tnfocusables; n++) { - if (tfocusables[n] && tfocusables[n]->quit && - !tfocusables[n]->quit(tfocusables[n])) { - quit = false; - break; + for (n = 0; n < tnfocusables; n++) { + if (tfocusables[n] && tfocusables[n]->quit && + !tfocusables[n]->quit(tfocusables[n])) { + quit = false; + break; + } } + + xfree(&tfocusables); } - - xfree(&tfocusables); ExitToShell(); break; } --- session.c Wed Jul 20 17:05:44 2022 +++ session.c Sun Jul 31 22:39:39 2022 @@ -88,7 +88,7 @@ session_create(char *node, char *via, struct node_func nsessions++; - session = xmalloczero(sizeof(struct session)); + session = xmalloczero(sizeof(struct session), "session_create"); session->uthread = uthread_add(session_run, session); if (!session->uthread) { xfree(&session); @@ -135,10 +135,11 @@ session_run(struct uthread *uthread, void *arg) return; } } - + session_output_view_or_printf(s, DB_TEXT_ISSUE_ID, "\r\nWelcome to %s (%s)\r\n\r\n", db->config.name, s->node); session_flush(s); + uthread_yield(); auth = session_login(s); if (auth == AUTH_USER_FAILED) { @@ -186,6 +187,7 @@ session_run(struct uthread *uthread, void *arg) s->user ? s->user->username : GUEST_USERNAME, session_today_tally.calls, ordinal(session_today_tally.calls)); session_flush(s); + uthread_yield(); main_menu: session_output_view_or_printf(s, DB_TEXT_MENU_ID, @@ -510,7 +512,7 @@ session_output_view_or_printf(struct session *session, return size; } - view = xmalloc(o->size + 1); + view = xmalloc(o->size + 1, "session_output_view_or_printf"); size = bile_read_object(db->bile, o, view, o->size); view[size] = '\0'; xfree(&o); @@ -714,7 +716,7 @@ session_field_input(struct session *session, unsigned session->abort_input = false; - field = xmalloczero(size); + field = xmalloczero(size, "session_field_input"); if (initial_input) { ipos = ilen = strlcpy(field, initial_input, size); @@ -860,7 +862,8 @@ session_login(struct session *s) if (s->autologin_username[0]) { session_printf(s, "{{#}}%s\r\n", s->autologin_username); session_flush(s); - username = xstrdup(s->autologin_username); + username = xstrdup(s->autologin_username, + "session_login username"); } else { session_flush(s); username = session_field_input(s, DB_USERNAME_LENGTH + 1, @@ -969,6 +972,8 @@ login_bail: xfree(&password); if (!s->ban_node_source) { if (session_idled_out(s)) { + session_log(s, "Login timed out after %d seconds", + db->config.max_login_seconds); session_printf(s, "\r\nLogin timed out after %d seconds\r\n", db->config.max_login_seconds); /* session_flush won't do anything since s->ending is set */ --- settings.c Fri Jul 29 22:17:16 2022 +++ settings.c Sun Jul 31 21:32:57 2022 @@ -58,7 +58,7 @@ struct_editor(struct session *s, struct struct_field * session_printf(s, "{{B}}Editor: %s{{/B}}\r\n", title); session_flush(s); - new_data = xmalloc(dsize); + new_data = xmalloc(dsize, "struct_editor"); memcpy(new_data, data, dsize); print_options: @@ -333,7 +333,8 @@ view_editor_show(size_t id, char *title) ((screenBits.bounds.bottom - height) / 2); bounds.bottom = bounds.top + height; - view_editor = xmalloczero(sizeof(struct view_editor)); + view_editor = xmalloczero(sizeof(struct view_editor), + "view_editor_show editor"); view_editor->view_id = id; CtoPstr(title); @@ -396,7 +397,7 @@ view_editor_show(size_t id, char *title) view_editor->horiz_scroller = NewControl(view_editor->win, &bounds, "\p", true, 1, 1, 1, scrollBarProc, 0L); - focusable = xmalloczero(sizeof(struct focusable)); + focusable = xmalloczero(sizeof(struct focusable), "focusable"); focusable->win = view_editor->win; focusable->cookie = view_editor; focusable->key_down = view_editor_key_down; --- signup.c Wed Jul 20 09:40:11 2022 +++ signup.c Sun Jul 31 21:34:15 2022 @@ -101,7 +101,7 @@ signup(struct session *s) break; } - user = xmalloczero(sizeof(struct user)); + user = xmalloczero(sizeof(struct user), "signup user"); strncpy(user->username, username, sizeof(user->username)); user->created_at = Time; user->is_enabled = 1; --- sysop.c Wed Jul 20 09:41:03 2022 +++ sysop.c Sun Jul 31 21:37:42 2022 @@ -135,7 +135,8 @@ sysop_edit_boards(struct session *s) if (dopts != NULL) xfree(&dopts); dopts = xmalloc(sizeof(opts) + - (db->nboards * sizeof(struct session_menu_option))); + (db->nboards * sizeof(struct session_menu_option)), + "sysop_edit_boards opts"); for (n = 0; n < db->nboards; n++) { board = &db->boards[n]; opt = &dopts[n]; @@ -152,7 +153,8 @@ sysop_edit_boards(struct session *s) switch (c) { case 'n': - board = xmalloczero(sizeof(struct board)); + board = xmalloczero(sizeof(struct board), + "sysop_edit_boards board"); board->id = bile_next_id(db->bile, DB_BOARD_RTYPE); board->restricted_posting = false; board->restricted_viewing = false; @@ -255,7 +257,8 @@ sysop_edit_folders(struct session *s) if (dopts != NULL) xfree(&dopts); dopts = xmalloc(sizeof(opts) + - (db->nboards * sizeof(struct session_menu_option))); + (db->nboards * sizeof(struct session_menu_option)), + "sysop_edit_folders opts"); for (n = 0; n < db->nfolders; n++) { folder = &db->folders[n]; opt = &dopts[n]; @@ -272,7 +275,8 @@ sysop_edit_folders(struct session *s) switch (c) { case 'n': - folder = xmalloczero(sizeof(struct folder)); + folder = xmalloczero(sizeof(struct folder), + "sysop_edit_folders folder"); folder->id = bile_next_id(db->bile, DB_FOLDER_RTYPE); folder->restricted_posting = false; folder->restricted_viewing = false; @@ -487,7 +491,8 @@ sysop_find_user_ids(size_t nall_user_ids, unsigned lon if (nuser_ids > limit) nuser_ids = limit; - *user_ids = xcalloc(sizeof(unsigned long), nuser_ids); + *user_ids = xcalloc(sizeof(unsigned long), nuser_ids, + "sysop_find_user_ids"); for (n = 0; n < nuser_ids; n++) { (*user_ids)[n] = all_user_ids[offset + n]; --- telnet.c Wed Jul 20 09:41:17 2022 +++ telnet.c Sun Jul 31 23:00:59 2022 @@ -165,7 +165,8 @@ telnet_init(void) /* pre-allocate nodes */ for (n = 0; n < MAX_TELNET_NODES; n++) { - telnet_nodes[n] = xmalloczero(sizeof(struct telnet_node)); + telnet_nodes[n] = xmalloczero(sizeof(struct telnet_node), + "telnet node"); telnet_nodes[n]->id = n; if (n == 0) @@ -174,7 +175,7 @@ telnet_init(void) if (db->config.trusted_proxy_ip != 0 && db->config.trusted_proxy_udp_port != 0) { - udp_ban_rcv_buf = xmalloc(UDP_BAN_RCV_BUF_SIZE); + udp_ban_rcv_buf = xmalloc(UDP_BAN_RCV_BUF_SIZE, "udp_ban_rcv_buf"); error = _UDPCreate(&udp_ban_pb, &udp_ban_stream, (Ptr)udp_ban_rcv_buf, UDP_BAN_RCV_BUF_SIZE, NULL, NULL, NULL, false); @@ -776,7 +777,7 @@ process_result: node->tcp_wds[0].length = node->escaped_obuflen; node->tcp_wds[1].ptr = 0; node->tcp_wds[1].length = 0; - + now = Ticks; error = _TCPSend(&node->send_pb, node->stream, node->tcp_wds, nil, nil, true); --- user.c Wed Jul 20 09:42:02 2022 +++ user.c Sun Jul 31 17:58:55 2022 @@ -56,7 +56,7 @@ user_cache_usernames(void) db->nusers = bile_count_by_type(db->bile, DB_USER_RTYPE); db->username_cache = xmalloczero(sizeof(struct username_cache) * - db->nusers); + db->nusers, "username_cache"); nuser = 0; while ((o = bile_get_nth_of_type(db->bile, nuser, DB_USER_RTYPE))) { @@ -107,7 +107,7 @@ user_find(unsigned long id) if (len != sizeof(struct user)) panic("user_find: bad user record size %lu != %lu", len, sizeof(struct user)); - user = xmalloczero(sizeof(struct user)); + user = xmalloczero(sizeof(struct user), "user_find"); memcpy(user, data, sizeof(struct user)); xfree(&data); return user; @@ -161,7 +161,7 @@ user_authenticate(struct user *user, const char *passw plen = strlen(password); slen = SHA256_DIGEST_STRING_LENGTH - 1 + plen; - salted = xmalloc(slen); + salted = xmalloc(slen, "user_authenticate"); memcpy(salted, user->password_salt, SHA256_DIGEST_STRING_LENGTH - 1); memcpy(salted + SHA256_DIGEST_STRING_LENGTH - 1, password, plen); @@ -200,7 +200,7 @@ user_set_password(struct user *user, const char *passw plen = strlen(password); slen = plen + sizeof(salt) - 1; - salted = xmalloc(slen); + salted = xmalloc(slen, "user_set_password"); memcpy(salted, salt, sizeof(salt) - 1); /* exclude null */ memcpy(salted + sizeof(salt) - 1, password, plen); SHA256Data((const u_int8_t *)salted, slen, hash); @@ -222,13 +222,13 @@ user_valid_username(struct user *user, char *username, char c; if (username == NULL) { - *error = xstrdup("username cannot be empty"); + *error = xstrdup("username cannot be empty", "user_valid_username"); return false; } len = strlen(username); if (len > DB_USERNAME_LENGTH) { - *error = xmalloc(61); + *error = xmalloc(61, "user_valid_username"); snprintf(*error, 60, "username cannot be more than %d characters", DB_USERNAME_LENGTH); return false; @@ -240,19 +240,20 @@ user_valid_username(struct user *user, char *username, if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')) { *error = xstrdup("username cannot contain non-alphanumeric " - "characters"); + "characters", "user_valid_username"); return false; } } if (strcasecmp(username, GUEST_USERNAME) == 0) { - *error = xstrdup("username is already in use"); + *error = xstrdup("username is already in use", + "user_valid_username"); return false; } if (!(user != NULL && user->is_sysop) && user_username_is_banned(username)) { - *error = xstrdup("username is not permitted"); + *error = xstrdup("username is not permitted", "user_valid_username"); return false; } @@ -261,7 +262,8 @@ user_valid_username(struct user *user, char *username, xfree(&ouser); if (user == NULL || ouser_id != user->id) { - *error = xstrdup("username is already in use"); + *error = xstrdup("username is already in use", + "user_valid_username"); return false; } } --- zmodem.c Thu Jul 21 09:02:46 2022 +++ zmodem.c Sun Jul 31 22:03:07 2022 @@ -243,7 +243,7 @@ ZCreateSender(struct session *session, FILE *fp, char if (!fp) return NULL; - zs = xmalloczero(sizeof(struct zmodem_session)); + zs = xmalloczero(sizeof(struct zmodem_session), "ZCreateSender"); zs->session = session; zs->file = fp; strlcpy(zs->file_name, file_name, sizeof(zs->file_name)); @@ -263,7 +263,7 @@ ZCreateReceiver(struct session *session, char *path) { struct zmodem_session *zs; - zs = xmalloczero(sizeof(struct zmodem_session)); + zs = xmalloczero(sizeof(struct zmodem_session), "ZCreateReceiver"); zs->session = session; zs->ZMode = IdZAutoR; zs->upload_file_path = path;