Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ lt-*.c
/src/test_bbs
/src/test_bwf
/src/test_hash_dict
/src/test_ip_mask
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([lbbs],[1.7.9])
AC_INIT([lbbs],[1.7.10])
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([m4])
Expand Down
10 changes: 9 additions & 1 deletion include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ enum log_level_t
LOG_LEVEL_DEBUG,
};

// Enable compile-time format string checking for log_* calls (GCC / Clang)
#if defined(__GNUC__)
#define LOG_PRINTF_FORMAT_ATTR __attribute__((format(printf, 4, 5)))
#else
#define LOG_PRINTF_FORMAT_ATTR
#endif

extern int log_begin(const char *common_log_file, const char *error_log_file);
extern void log_end(void);

extern int log_printf(enum log_level_t log_level, const char *app_file, int app_line, const char *format, ...);
extern int log_printf(enum log_level_t log_level, const char *app_file, int app_line, const char *format, ...)
LOG_PRINTF_FORMAT_ATTR;

#define log_common(...) log_printf(LOG_LEVEL_COMMON, __FILE__, __LINE__, __VA_ARGS__)
#define log_error(...) log_printf(LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bin_PROGRAMS = bbsd
test_PROGRAMS = test_trie_dict test_file_loader test_section_list test_lml test_ssh_server test_article_favor test_article_view_log \
test_memory_pool test_bbs test_bwf test_hash_dict
test_memory_pool test_bbs test_bwf test_hash_dict test_ip_mask

testdir = ${prefix}/test

Expand Down Expand Up @@ -31,6 +31,7 @@ test_memory_pool_SOURCES = log.c memory_pool.c test_memory_pool.c
test_bbs_SOURCES = bbs.c log.c test_bbs.c user_priv.c
test_bwf_SOURCES = bwf.c log.c test_bwf.c
test_hash_dict_SOURCES = hash_dict.c log.c memory_pool.c test_hash_dict.c
test_ip_mask_SOURCES = ip_mask.c test_ip_mask.c

AM_CFLAGS = -I${srcdir}/../include -I${srcdir}/../utils/game ${LIBSSH_CFLAGS} ${MYSQLCLIENT_CFLAGS} ${SYSTEMD_CFLAGS} ${LIBPCRE2_CFLAGS} ${ICONV_CFLAGS} \
-std=c17 -Wall -Werror -Wformat -Wpedantic -Wformat-security -Wconversion \
Expand Down
2 changes: 1 addition & 1 deletion src/article_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons

if (header_len != cache.line_offsets[header_line_cnt])
{
log_debug("Header of article(aid=%d) is truncated from %ld to %ld\n, body_line=%ld, body_line_limit=%ld",
log_debug("Header of article(aid=%d) is truncated from %ld to %ld\n, body_line=%ld, body_line_limit=%d",
p_article->aid, header_len, cache.line_offsets[header_line_cnt],
header_line_cnt, MAX_SPLIT_FILE_LINES);
header_len = (size_t)cache.line_offsets[header_line_cnt];
Expand Down
1 change: 1 addition & 0 deletions src/article_del.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)
if (p_section == NULL || p_article == NULL)
{
log_error("NULL pointer error");
return -1;
}

if (p_article->excerption) // Delete is not allowed
Expand Down
22 changes: 21 additions & 1 deletion src/article_post.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)
if (p_section == NULL || p_article_new == NULL)
{
log_error("NULL pointer error");
return -1;
}

if (!checkpriv(&BBS_priv, p_section->sid, S_POST))
Expand Down Expand Up @@ -453,6 +454,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI
if (p_section == NULL || p_article == NULL)
{
log_error("NULL pointer error");
return -1;
}

if (p_article->excerption) // Modify is not allowed
Expand Down Expand Up @@ -521,6 +523,13 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI

reply_note = atoi(row[2]);
}
else
{
log_error("Article content not found (aid=%d)", p_article->aid);
ret = -1;
goto cleanup;
}

mysql_free_result(rs);
rs = NULL;

Expand Down Expand Up @@ -754,6 +763,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC
int sign_id = 0;
int reply_note = 0;
int full_quote = 0;
int cid = 0;
long len;
int ch;
char *p, *q;
Expand All @@ -770,6 +780,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC
if (p_section == NULL || p_article == NULL)
{
log_error("NULL pointer error");
return -1;
}

if (!checkpriv(&BBS_priv, p_section->sid, S_POST))
Expand Down Expand Up @@ -856,6 +867,8 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC

if ((row = mysql_fetch_row(rs)))
{
cid = atoi(row[0]);

content = malloc(ARTICLE_CONTENT_MAX_LEN);
if (content == NULL)
{
Expand All @@ -879,6 +892,13 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC
// Remove control sequence
len = str_filter(content_f, 0);
}
else
{
log_error("Article content not found (aid=%d)", p_article->aid);
ret = -1;
goto cleanup;
}

mysql_free_result(rs);
rs = NULL;

Expand Down Expand Up @@ -1007,7 +1027,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC
p_editor_data = editor_data_load(content);
if (p_editor_data == NULL)
{
log_error("editor_data_load(aid=%d, cid=%d) error", p_article->aid, atoi(row[0]));
log_error("editor_data_load(aid=%d, cid=%d) error", p_article->aid, cid);
ret = -1;
goto cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/article_view_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc)
p_view_log->aid_base = malloc(sizeof(int32_t) * mysql_num_rows(rs));
if (p_view_log->aid_base == NULL)
{
log_error("malloc(INT32 * %d) error: OOM", mysql_num_rows(rs));
log_error("malloc(INT32 * %lu) error: OOM", (unsigned long)mysql_num_rows(rs));
mysql_free_result(rs);
mysql_close(db);
return -4;
Expand Down
4 changes: 2 additions & 2 deletions src/bbs_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int load_bbsnet_conf(const char *file_config)
p_menu_item = get_menu_item_by_id(&bbsnet_menu, menu_item_id);
if (p_menu_item == NULL)
{
log_error("get_menu_item_by_id(%d) error: NULL pointer", menu_item_id);
log_error("get_menu_item_by_id(%lu) error: NULL pointer", menu_item_id);
fclose(fin);
unload_bbsnet_conf();
return -3;
Expand Down Expand Up @@ -1383,7 +1383,7 @@ static int bbsnet_connect(int n)
#ifdef HAVE_SYS_EPOLL_H
if (epollfd != -1 && close(epollfd) < 0)
{
log_error("close(epoll) error (%d)");
log_error("close(epoll) error (%d)", errno);
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions src/bwf.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int bwf_load(const char *filename)
len_line = strnlen(line, sizeof(line) - 1);
if (!feof(fp) && line[len_line - 1] != '\n')
{
log_error("Data line %d (len=%d) is truncated", line_id, len_line);
log_error("Data line %d (len=%zu) is truncated", line_id, len_line);
bwf_pattern_str[0] = '\0';
return -3;
}
Expand All @@ -80,7 +80,7 @@ int bwf_load(const char *filename)

if (len_line + 2 > sizeof(bwf_pattern_str) - 1 - (size_t)(p - bwf_pattern_str))
{
log_error("Data in %s exceed length limit %d", filename, sizeof(bwf_pattern_str) - 1);
log_error("Data in %s exceed length limit %zu", filename, sizeof(bwf_pattern_str) - 1);
bwf_pattern_str[0] = '\0';
return -3;
}
Expand Down Expand Up @@ -168,13 +168,13 @@ int check_badwords(char *str, char c_mask)
i = ret - 1;
if (ovector[i * 2] == -1 || ovector[i * 2 + 1] == -1)
{
log_error("Bug: match pattern #%d of %d with invalid offsets [%d, %d)",
log_error("Bug: match pattern #%d of %d with invalid offsets [%zu, %zu)",
i, match_count, ovector[i * 2], ovector[i * 2 + 1]);
ret = -2;
}
else
{
log_debug("Debug: match pattern #%d of %d at offsets [%d, %d]",
log_debug("Debug: match pattern #%d of %d at offsets [%zu, %zu]",
i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]);
memset(str + ovector[i * 2], c_mask, ovector[i * 2 + 1] - ovector[i * 2]);
total_match_count++;
Expand Down
6 changes: 3 additions & 3 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ EDITOR_DATA *editor_data_load(const char *p_data)
p_data_line = memory_pool_alloc(p_mp_data_line);
if (p_data_line == NULL)
{
log_error("memory_pool_alloc() error: i = %d", i);
log_error("memory_pool_alloc() error: i = %ld", i);
// Cleanup
editor_data_cleanup(p_editor_data);
return NULL;
Expand Down Expand Up @@ -169,7 +169,7 @@ long editor_data_save(const EDITOR_DATA *p_editor_data, char *p_data, size_t buf
{
if (current_pos + p_editor_data->display_line_lengths[i] + 1 > buf_len)
{
log_error("Data buffer not longer enough %d > %d", current_pos + p_editor_data->display_line_lengths[i] + 1, buf_len);
log_error("Data buffer not longer enough %ld > %zu", current_pos + p_editor_data->display_line_lengths[i] + 1, buf_len);
p_data[current_pos] = '\0';
return -2;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p
// Insert blank display line after last_display_line
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES)
{
log_debug("display_line_total over limit %d >= %d", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);
log_debug("display_line_total over limit %ld >= %d", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES);

// Terminate prior display line with \n, to avoid error on cleanup
if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/file_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int load_file(const char *filename)
}
if (ftruncate(fd, (off_t)size) == -1)
{
log_error("ftruncate(size=%d) error (%d)", size, errno);
log_error("ftruncate(size=%zu) error (%d)", size, errno);
close(fd);
return -2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char

if (out_bytes <= 0)
{
log_error("No enough free space in p_conv, conv_len=%d, conv_size=%d", *p_conv_len, conv_size);
log_error("No enough free space in p_conv, conv_len=%d, conv_size=%zu", *p_conv_len, conv_size);
return -2;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lml.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int lml_render(const char *str_in, char *str_out, int buf_len, int width, int qu
#ifdef _DEBUG
if (i >= str_in_len)
{
log_error("Bug: i(%d) >= str_in_len(%d)", i, str_in_len);
log_error("Bug: i(%d) >= str_in_len(%zu)", i, str_in_len);
break;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ int main(int argc, char *argv[])
// Get EULA modification tm
if (stat(DATA_EULA, &file_stat) == -1)
{
log_error("stat(%s) error", DATA_EULA, errno);
log_error("stat(%s) error (%d)", DATA_EULA, errno);
goto cleanup;
}
BBS_eula_tm = file_stat.st_mtim.tv_sec;
Expand Down
Loading
Loading