jcs
/subtext
/amendments
/643
board: Minor bugfixes, memory leaks
jcs made amendment 643 1 day ago
--- board.c Fri Sep 18 21:08:06 2026
+++ board.c Tue Sep 22 14:50:18 2026
@@ -174,17 +174,27 @@ board_list_boards(struct session *s)
"#:View Board L:List Boards Q:Return ?:Help";
struct board *lboards = NULL, tboard;
size_t nlboards;
- char title[] = "List Boards";
+ char title[] = "Message Boards";
char c;
short an, n, i, j;
bool done, show_list, show_help;
+ if (db->nboards == 0) {
+ session_printf(s, "No boards created.\n");
+ session_flush(s);
+ return;
+ }
+
lboards = xcalloc(sizeof(struct board), db->nboards);
if (lboards == NULL)
return;
nlboards = 0;
for (n = 0; n < db->nboards; n++) {
+ if (db->boards[n].restricted_viewing &&
+ !(s->user && s->user->is_sysop))
+ continue;
+
if (db->boards[n].ftn_area[0] == '\0') {
memcpy(&lboards[nlboards], &db->boards[n],
sizeof(struct board));
@@ -207,8 +217,6 @@ board_list_boards(struct session *s)
show_list = true;
show_help = false;
done = false;
-
- snprintf(title, sizeof(title), "Message Boards");
while (!done && !s->ending) {
if (show_list) {
@@ -284,6 +292,12 @@ board_list_ftn_areas(struct session *s)
return;
}
+ if (db->nboards == 0) {
+ session_printf(s, "No %s areas defined.\n", db->config.ftn_network);
+ session_flush(s);
+ return;
+ }
+
snprintf(opts[1].title, sizeof(opts[1].title), "List %s Areas",
db->config.ftn_network);
@@ -293,6 +307,10 @@ board_list_ftn_areas(struct session *s)
nfboards = 0;
for (n = 0; n < db->nboards; n++) {
+ if (db->boards[n].restricted_viewing &&
+ !(s->user && s->user->is_sysop))
+ continue;
+
if (db->boards[n].ftn_area[0]) {
memcpy(&fboards[nfboards], &db->boards[n],
sizeof(struct board));
@@ -402,12 +420,13 @@ board_show(struct session *s, short id, char *prompt_p
}
}
- if (!board) {
+ if (!board ||
+ (board->restricted_viewing && !(s->user && s->user->is_sysop))) {
session_printf(s, "Invalid board\r\n");
session_flush(s);
return;
}
-
+
page = 0;
find_post_ids = true;
show_list = true;
@@ -745,8 +764,8 @@ post_compose_start:
session_flush(s);
} else if (ftn_parent_post) {
session_printf(s, "{{B}}Subject:{{/B}}{{#}} %s%s\r\n",
- strncmp(ftn_parent_post->subject, "Re:", 3) == 0 ? "" : "Re: ",
- ftn_parent_post->subject);
+ strncasecmp(ftn_parent_post->subject, "Re:", 3) == 0 ?
+ "" : "Re: ", ftn_parent_post->subject);
session_flush(s);
} else {
if (initial_subject && !thread->subject) {
@@ -890,9 +909,9 @@ board_post_read(struct session *s, struct board *board
static const char prompt_help[] =
"<:Newer >:Older R:Reply S:Show D:Delete L:List Q:Return ?:Help";
char time[32], prompt[7 + member_size(struct board, name) + 8];
- struct board_thread thread;
- struct board_post post;
- struct board_ftn_post fpost;
+ struct board_thread thread = { 0 };
+ struct board_post post = { 0 };
+ struct board_ftn_post fpost = { 0 };
struct username_cache *sender;
struct session_menu_option *dopts = NULL;
size_t size, plain_post_size, j;
@@ -908,6 +927,16 @@ board_post_read(struct session *s, struct board *board
memcpy(dopts, opts, sizeof(opts));
show_post:
+ if (fpost.body != NULL)
+ xfree(&fpost.body);
+ if (post.body != NULL)
+ xfree(&post.body);
+ if (thread.subject != NULL)
+ xfree(&thread.subject);
+ if (thread.post_ids != NULL)
+ xfree(&thread.post_ids);
+ if (thread.parent_post_ids != NULL)
+ xfree(&thread.parent_post_ids);
if (board->ftn_area[0]) {
size = bile_read_alloc(board->bile, BOARD_FTN_POST_RTYPE, id,
&data);
@@ -954,7 +983,7 @@ show_post:
else {
/* strip out renegade-style pipe color codes ("abc|01def") */
for (j = 0; j < fpost.body_size; j++) {
- if (fpost.body[j] == '|' &&
+ if (fpost.body[j] == '|' && j + 2 < fpost.body_size &&
fpost.body[j + 1] >= '0' && fpost.body[j + 1] <= '9' &&
fpost.body[j + 2] >= '0' && fpost.body[j + 2] <= '9') {
j += 2;
@@ -1048,7 +1077,7 @@ show_post:
session_flush(s);
cc = session_input_char(s);
- if (cc == 'y' || c == 'Y') {
+ if (cc == 'y' || cc == 'Y') {
session_printf(s, "%c\r\n", cc);
session_flush(s);
@@ -1222,8 +1251,8 @@ board_post_create(struct board *board, struct board_th
if (ftn_parent_post) {
snprintf(ftn_post.subject, sizeof(ftn_post.subject),
"%s%s",
- strncmp(ftn_parent_post->subject, "Re:", 3) == 0 ? "" : "Re: ",
- ftn_parent_post->subject);
+ strncasecmp(ftn_parent_post->subject, "Re:", 3) == 0 ?
+ "" : "Re: ", ftn_parent_post->subject);
strlcpy(ftn_post.reply, ftn_parent_post->msgid_orig,
sizeof(ftn_post.reply));
strlcpy(ftn_post.to, ftn_parent_post->from,
@@ -1419,8 +1448,10 @@ board_delete_post(struct board *board, struct board_po
return;
new_parent_post_ids = xcalloc(thread->nposts - 1,
sizeof(unsigned long));
- if (new_parent_post_ids == NULL)
+ if (new_parent_post_ids == NULL) {
+ xfree(&new_post_ids);
return;
+ }
for (n = 0, nn = 0; n < thread->nposts; n++) {
if (thread->post_ids[n] == post->id)
@@ -1548,7 +1579,7 @@ board_index_sorted_post_ids(struct board *board,
struct board_thread thread;
size_t ret, size, i, j, n, npost_ids, nthread_ids;
unsigned long *post_ids = NULL, *thread_ids = NULL;
- struct board_id_time_map *id_map, tmp_id_map;
+ struct board_id_time_map *id_map = NULL, tmp_id_map;
struct thread_time_map *thread_map = NULL, tmp_thread_map;
char *data;
bool failed = false;
@@ -1743,7 +1774,7 @@ board_toss_ftn_message(struct board *board,
struct bile_object *o;
struct board_ftn_post post;
struct fidopkt_msgid msgid;
- unsigned long *post_ids;
+ unsigned long *post_ids = NULL;
char *pdata;
size_t asize, cache_size, psize, npost_ids;
short n, ret, bret;
@@ -1877,7 +1908,9 @@ done:
}
if (msgid_cache != NULL)
xfree(&msgid_cache);
-
+ if (post_ids != NULL)
+ xfree(&post_ids);
+
return ret;
}
@@ -1938,23 +1971,35 @@ board_prune_old_posts(struct board *board)
continue;
ret = bile_unmarshall_object(board->bile,
board_post_object_fields, nboard_post_object_fields,
- data, size, &post, sizeof(post), false);
+ data, size, &post, sizeof(post), true);
xfree(&data);
if (ret == BILE_ERR_NO_MEMORY)
goto done;
size = bile_read_alloc(board->bile, BOARD_THREAD_RTYPE,
post.thread_id, &data);
- if (!size)
+ if (!size) {
+ if (post.body != NULL)
+ xfree(&post.body);
continue;
+ }
ret = bile_unmarshall_object(board->bile,
board_thread_object_fields, nboard_thread_object_fields,
- data, size, &thread, sizeof(thread), false);
+ data, size, &thread, sizeof(thread), true);
xfree(&data);
if (ret == BILE_ERR_NO_MEMORY)
goto done;
board_delete_post(board, &post, &thread);
+
+ if (post.body != NULL)
+ xfree(&post.body);
+ if (thread.subject != NULL)
+ xfree(&thread.subject);
+ if (thread.post_ids != NULL)
+ xfree(&thread.post_ids);
+ if (thread.parent_post_ids != NULL)
+ xfree(&thread.parent_post_ids);
}
deleted++;