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
5 changes: 4 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Short, specific pointers to help an AI coding agent be productive in this repo.
**Build & Test**
- **Install deps**: libssh, libpcre2 and a MySQL/MariaDB client dev package (e.g., libssh-dev, libpcre2-dev, libmariadb-dev or libmysqlclient-dev). CI also installs `libsystemd-dev`.
- **Build**: `autoreconf --install --force` then `./configure --enable-systemd --disable-silent-rules` and `make`.
- **Run tests**: `make check` (tests are custom binaries built under `src/`, e.g. `test_trie_dict`). CI runs `make check` and `make distcheck` (see [.github/workflows/makefile.yml](.github/workflows/makefile.yml#L1-L40)).
- **Testers**: test programs are declared as `test_PROGRAMS` in [src/Makefile.am](src/Makefile.am#L1-L40), so `make` builds them but `make check` does not execute them (there is no `TESTS` variable) — CI only compiles them. Run them manually from `src/` (they resolve `../log` and `../data` relative to that directory): `cd src && ./test_trie_dict`.
- Non-interactive, database-free testers: `test_trie_dict`, `test_file_loader`, `test_lml`, `test_memory_pool`, `test_bbs`, `test_bwf`, `test_hash_dict`, `test_ip_mask`. (`test_hash_dict` is heavy: it allocates ~2.7 GB and takes tens of seconds.)
- Interactive and/or DB-dependent testers (need a configured MySQL/MariaDB and a terminal): `test_section_list`, `test_article_favor`, `test_article_view_log`, `test_ssh_server`.
- **CI**: runs `make`, `make check` and `make distcheck` (see [.github/workflows/makefile.yml](.github/workflows/makefile.yml#L1-L80)).

**Run & Debug**
- **Server binary**: `src/bbsd` (entry: [src/main.c](src/main.c#L1-L60)).
Expand Down
2 changes: 2 additions & 0 deletions src/article_favor.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ int article_favor_load(int uid, ARTICLE_FAVOR *p_favor, int keep_inc)
if (mysql_query(db, sql) != 0)
{
log_error("Query article_favorite error: %s", mysql_error(db));
mysql_close(db);
return -3;
}
if ((rs = mysql_use_result(db)) == NULL)
{
log_error("Get article_favorite data failed");
mysql_close(db);
return -3;
}

Expand Down
2 changes: 2 additions & 0 deletions src/article_view_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc)
if (mysql_query(db, sql) != 0)
{
log_error("Query view_article_log error: %s", mysql_error(db));
mysql_close(db);
return -3;
}
if ((rs = mysql_store_result(db)) == NULL)
{
log_error("Get view_article_log data failed");
mysql_close(db);
return -3;
}

Expand Down
2 changes: 2 additions & 0 deletions src/bbs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ int bbs_logout(void)

if (user_online_exp(db) < 0)
{
mysql_close(db);
return -2;
}

Expand All @@ -140,6 +141,7 @@ int bbs_session_cleanup(void)

if (user_online_del(db) < 0)
{
mysql_close(db);
return -2;
}

Expand Down
11 changes: 11 additions & 0 deletions src/bwf.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int bwf_load(const char *filename)
{
log_error("Data line %d (len=%zu) is truncated", line_id, len_line);
bwf_pattern_str[0] = '\0';
fclose(fp);
return -3;
}

Expand All @@ -82,6 +83,7 @@ int bwf_load(const char *filename)
{
log_error("Data in %s exceed length limit %zu", filename, sizeof(bwf_pattern_str) - 1);
bwf_pattern_str[0] = '\0';
fclose(fp);
return -3;
}

Expand Down Expand Up @@ -143,6 +145,11 @@ int check_badwords(char *str, char c_mask)
}

match_data = pcre2_match_data_create_from_pattern(bwf_code, NULL);
if (match_data == NULL)
{
log_error("pcre2_match_data_create_from_pattern() error: OOM");
return -1;
}

while (1)
{
Expand All @@ -155,10 +162,13 @@ int check_badwords(char *str, char c_mask)
else if (ret < 0)
{
log_error("pcre2_match() error: %d", ret);
break;
}
else if (ret == 0)
{
log_error("Vector of offsets is too small");
ret = -2;
break;
}
else // ret >= 1
{
Expand All @@ -171,6 +181,7 @@ int check_badwords(char *str, char c_mask)
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;
break;
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion src/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ int check_user(const char *username, const char *password)
if (setenv("TZ", user_tz_env, 1) == -1)
{
log_error("setenv(TZ = %s) error %d", user_tz_env, errno);
return -3;
ret = -3;
goto cleanup;
}

tzset();
Expand Down Expand Up @@ -620,6 +621,7 @@ int user_online_update(const char *action)
if (mysql_query(db, sql) != 0)
{
log_error("Update user_online error: %s", mysql_error(db));
mysql_close(db);
return -2;
}

Expand Down
Loading
Loading