summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-25 19:42:27 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-25 19:42:27 +0100
commit5bc4c0663576fd99bb06068e6dfd624690865c89 (patch)
treee1e90e6966abebf960ed9c9d4ed0937be22961ff
parent33b095eb26ab8be3af48d8bd034262cd5ab03a04 (diff)
Be stricter about const char*, Wwrite-strings will warn in the future and we don't want to try to overwrite string literals
-rw-r--r--Makefile6
-rw-r--r--opentracker.c2
-rw-r--r--ot_accesslist.c8
-rw-r--r--ot_accesslist.h6
-rw-r--r--ot_config.c12
-rw-r--r--ot_config.h8
-rw-r--r--ot_http.c10
-rw-r--r--ot_http.h2
-rw-r--r--ot_stats.c2
-rw-r--r--proxy.c2
-rw-r--r--scan_urlencoded_query.h4
-rw-r--r--tests/runner.c1
-rw-r--r--tests/stubs.c9
-rw-r--r--tests/test.h1
-rw-r--r--trackerlogic.c2
-rw-r--r--trackerlogic.h2
16 files changed, 44 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 55be5ba..00a9f93 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse H
64OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage 64OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
65OPTS_production=-O3 65OPTS_production=-O3
66 66
67CFLAGS+=-I$(LIBOWFAT_HEADERS) -DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra #-ansi -pedantic 67CFLAGS+=-I$(LIBOWFAT_HEADERS) -DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic
68LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread 68LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread
69 69
70BINARY =opentracker 70BINARY =opentracker
@@ -119,8 +119,8 @@ $(OBJECTS_proxy_debug): $(HEADERS)
119# has to. tests/stubs.c supplies the few symbols those modules reference but 119# has to. tests/stubs.c supplies the few symbols those modules reference but
120# the tests never reach. 120# the tests never reach.
121TESTBIN=tests/runner 121TESTBIN=tests/runner
122TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_scan_urlencoded_query.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c 122TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_scan_urlencoded_query.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c
123TEST_UNITS=scan_urlencoded_query.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c 123TEST_UNITS=scan_urlencoded_query.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c
124TEST_HEADERS=tests/test.h $(HEADERS) 124TEST_HEADERS=tests/test.h $(HEADERS)
125# Tests reach code that sits behind feature flags, so the units under test are 125# Tests reach code that sits behind feature flags, so the units under test are
126# built with those features enabled. A test binary is not a production binary. 126# built with those features enabled. A test binary is not a production binary.
diff --git a/opentracker.c b/opentracker.c
index 0af0d17..96a265a 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -305,7 +305,7 @@ static void listen_bind_one(ot_listen *entry) {
305 305
306#ifdef _DEBUG 306#ifdef _DEBUG
307 { 307 {
308 char *protos[] = {"TCP", "UDP", "UDP mcast"}; 308 const char *protos[] = {"TCP", "UDP", "UDP mcast"};
309 char _debug[512]; 309 char _debug[512];
310 int off = snprintf(_debug, sizeof(_debug), "Binding socket type %s to address [", protos[entry->proto]); 310 int off = snprintf(_debug, sizeof(_debug), "Binding socket type %s to address [", protos[entry->proto]);
311 off += ip_format(_debug + off, entry->ip); 311 off += ip_format(_debug + off, entry->ip);
diff --git a/ot_accesslist.c b/ot_accesslist.c
index 2465ada..d7e88ee 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -32,10 +32,10 @@
32 32
33/* GLOBAL VARIABLES */ 33/* GLOBAL VARIABLES */
34#ifdef WANT_ACCESSLIST 34#ifdef WANT_ACCESSLIST
35char *g_accesslist_filename = NULL; 35const char *g_accesslist_filename = NULL;
36#ifdef WANT_DYNAMIC_ACCESSLIST 36#ifdef WANT_DYNAMIC_ACCESSLIST
37char *g_accesslist_pipe_add = NULL; 37const char *g_accesslist_pipe_add = NULL;
38char *g_accesslist_pipe_delete = NULL; 38const char *g_accesslist_pipe_delete = NULL;
39#endif 39#endif
40static pthread_mutex_t g_accesslist_mutex; 40static pthread_mutex_t g_accesslist_mutex;
41 41
@@ -272,7 +272,7 @@ static void *accesslist_worker(void *args) {
272 272
273#ifdef WANT_DYNAMIC_ACCESSLIST 273#ifdef WANT_DYNAMIC_ACCESSLIST
274static pthread_t thread_adder_id, thread_deleter_id; 274static pthread_t thread_adder_id, thread_deleter_id;
275static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic *adding_to, ot_accesslist *_Atomic *removing_from) { 275static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_Atomic *adding_to, ot_accesslist *_Atomic *removing_from) {
276 struct stat st; 276 struct stat st;
277 277
278 if (!stat(fifoname, &st)) { 278 if (!stat(fifoname, &st)) {
diff --git a/ot_accesslist.h b/ot_accesslist.h
index 30aaebd..9dfdd95 100644
--- a/ot_accesslist.h
+++ b/ot_accesslist.h
@@ -23,10 +23,10 @@ void accesslist_cleanup(void);
23 line, and return how many were written to dest */ 23 line, and return how many were written to dest */
24size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len); 24size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len);
25 25
26extern char *g_accesslist_filename; 26extern const char *g_accesslist_filename;
27#ifdef WANT_DYNAMIC_ACCESSLIST 27#ifdef WANT_DYNAMIC_ACCESSLIST
28extern char *g_accesslist_pipe_add; 28extern const char *g_accesslist_pipe_add;
29extern char *g_accesslist_pipe_delete; 29extern const char *g_accesslist_pipe_delete;
30#endif 30#endif
31 31
32#else 32#else
diff --git a/ot_config.c b/ot_config.c
index 43c07c5..e9666f9 100644
--- a/ot_config.c
+++ b/ot_config.c
@@ -22,10 +22,10 @@
22#include "ot_stats.h" 22#include "ot_stats.h"
23#include "trackerlogic.h" 23#include "trackerlogic.h"
24 24
25char *g_redirecturl; 25const char *g_redirecturl;
26char *g_serverdir; 26const char *g_serverdir;
27char *g_serveruser; 27const char *g_serveruser;
28char *g_statefile; 28const char *g_statefile;
29 29
30#define OT_LISTEN_INHERIT (-1) 30#define OT_LISTEN_INHERIT (-1)
31 31
@@ -122,13 +122,13 @@ static int listen_scan_options(char *p, int *shared, int *workers) {
122} 122}
123 123
124 124
125char *set_config_option(char **option, char *value) { 125static const char *set_config_option(const char **option, char *value) {
126#ifdef _DEBUG 126#ifdef _DEBUG
127 fprintf(stderr, "Setting config option: %s\n", value); 127 fprintf(stderr, "Setting config option: %s\n", value);
128#endif 128#endif
129 while (isspace(*value)) 129 while (isspace(*value))
130 ++value; 130 ++value;
131 free(*option); 131 free((char *)*option);
132 return *option = strdup(value); 132 return *option = strdup(value);
133} 133}
134 134
diff --git a/ot_config.h b/ot_config.h
index ab25e2c..059573a 100644
--- a/ot_config.h
+++ b/ot_config.h
@@ -22,10 +22,10 @@ typedef struct {
22 int64_t sock; 22 int64_t sock;
23} ot_listen; 23} ot_listen;
24 24
25extern char *g_redirecturl; 25extern const char *g_redirecturl;
26extern char *g_serverdir; 26extern const char *g_serverdir;
27extern char *g_serveruser; 27extern const char *g_serveruser;
28extern char *g_statefile; 28extern const char *g_statefile;
29 29
30/* Reads the command line and every config file it names. Exits on error. */ 30/* Reads the command line and every config file it names. Exits on error. */
31void config_parse(int argc, char **argv); 31void config_parse(int argc, char **argv);
diff --git a/ot_http.c b/ot_http.c
index 6448860..fc27eb8 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -37,9 +37,9 @@
37 37
38#define OT_MAXMULTISCRAPE_COUNT 64 38#define OT_MAXMULTISCRAPE_COUNT 64
39#define OT_BATCH_LIMIT (1024 * 1024 * 16) 39#define OT_BATCH_LIMIT (1024 * 1024 * 16)
40extern char *g_redirecturl; 40extern const char *g_redirecturl;
41 41
42char *g_stats_path; 42const char *g_stats_path;
43ssize_t g_stats_path_len; 43ssize_t g_stats_path_len;
44 44
45enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; 45enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 };
@@ -125,9 +125,9 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) {
125#define HTTPERROR_404 return http_issue_error(sock, ws, CODE_HTTPERROR_404) 125#define HTTPERROR_404 return http_issue_error(sock, ws, CODE_HTTPERROR_404)
126#define HTTPERROR_500 return http_issue_error(sock, ws, CODE_HTTPERROR_500) 126#define HTTPERROR_500 return http_issue_error(sock, ws, CODE_HTTPERROR_500)
127ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) { 127ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) {
128 char *error_code[] = {"302 Found", "400 Invalid Request", "400 Invalid Request", "400 Invalid Request", "402 Payment Required", 128 const char *error_code[] = {"302 Found", "400 Invalid Request", "400 Invalid Request", "400 Invalid Request", "402 Payment Required",
129 "403 Not Modest", "403 Access Denied", "404 Not Found", "500 Internal Server Error"}; 129 "403 Not Modest", "403 Access Denied", "404 Not Found", "500 Internal Server Error"};
130 char *title = error_code[code]; 130 const char *title = error_code[code];
131 131
132 ws->reply = ws->outbuf; 132 ws->reply = ws->outbuf;
133 if (code == CODE_HTTPERROR_302) 133 if (code == CODE_HTTPERROR_302)
@@ -491,7 +491,7 @@ unsigned long long numwants[201];
491#endif 491#endif
492 492
493#if defined(WANT_KEEPALIVE) || defined(WANT_IP_FROM_PROXY) 493#if defined(WANT_KEEPALIVE) || defined(WANT_IP_FROM_PROXY)
494static char *http_header(char *data, size_t byte_count, char *header) { 494static char *http_header(char *data, size_t byte_count, const char *header) {
495 size_t i; 495 size_t i;
496 long sl = strlen(header); 496 long sl = strlen(header);
497 for (i = 0; i + sl + 2 < byte_count; ++i) { 497 for (i = 0; i + sl + 2 < byte_count; ++i) {
diff --git a/ot_http.h b/ot_http.h
index 965820f..abad83a 100644
--- a/ot_http.h
+++ b/ot_http.h
@@ -37,7 +37,7 @@ ssize_t http_handle_request(const int64_t s, struct ot_workstruct *ws);
37ssize_t http_sendiovecdata(const int64_t s, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial); 37ssize_t http_sendiovecdata(const int64_t s, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial);
38ssize_t http_issue_error(const int64_t s, struct ot_workstruct *ws, int code); 38ssize_t http_issue_error(const int64_t s, struct ot_workstruct *ws, int code);
39 39
40extern char *g_stats_path; 40extern const char *g_stats_path;
41extern ssize_t g_stats_path_len; 41extern ssize_t g_stats_path_len;
42 42
43#endif 43#endif
diff --git a/ot_stats.c b/ot_stats.c
index f938e91..6589aef 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -53,7 +53,7 @@ static unsigned long long ot_full_scrape_count;
53static unsigned long long ot_full_scrape_request_count; 53static unsigned long long ot_full_scrape_request_count;
54static unsigned long long ot_full_scrape_size; 54static unsigned long long ot_full_scrape_size;
55static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; 55static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT];
56static char *ot_failed_request_names[] = { 56static const char *ot_failed_request_names[] = {
57 "302 Redirect", "400 Parse Error", "400 Invalid Parameter", "400 Invalid Parameter (compact=0)", "400 Not Modest", 57 "302 Redirect", "400 Parse Error", "400 Invalid Parameter", "400 Invalid Parameter (compact=0)", "400 Not Modest",
58 "402 Payment Required", "403 Access Denied", "404 Not found", "500 Internal Server Error"}; 58 "402 Payment Required", "403 Access Denied", "404 Not found", "500 Internal Server Error"};
59static unsigned long long ot_renewed[OT_PEER_TIMEOUT]; 59static unsigned long long ot_renewed[OT_PEER_TIMEOUT];
diff --git a/proxy.c b/proxy.c
index a870c63..219d926 100644
--- a/proxy.c
+++ b/proxy.c
@@ -72,7 +72,7 @@ static void *livesync_worker(void *args);
72static void *streamsync_worker(void *args); 72static void *streamsync_worker(void *args);
73static void livesync_proxytell(uint8_t prefix, uint8_t *info_hash, uint8_t *peer); 73static void livesync_proxytell(uint8_t prefix, uint8_t *info_hash, uint8_t *peer);
74 74
75void exerr(char *message) { 75void exerr(const char *message) {
76 fprintf(stderr, "%s\n", message); 76 fprintf(stderr, "%s\n", message);
77 exit(111); 77 exit(111);
78} 78}
diff --git a/scan_urlencoded_query.h b/scan_urlencoded_query.h
index d0929cf..f71752d 100644
--- a/scan_urlencoded_query.h
+++ b/scan_urlencoded_query.h
@@ -11,8 +11,8 @@
11#include <sys/types.h> 11#include <sys/types.h>
12 12
13typedef struct { 13typedef struct {
14 char *key; 14 const char *key;
15 int value; 15 int value;
16} ot_keywords; 16} ot_keywords;
17 17
18typedef enum { 18typedef enum {
diff --git a/tests/runner.c b/tests/runner.c
index db62246..972a56a 100644
--- a/tests/runner.c
+++ b/tests/runner.c
@@ -23,6 +23,7 @@ static const struct module modules[] = {{"scan_urlencoded_query", test_scan_urle
23 {"ot_buf", test_buf}, 23 {"ot_buf", test_buf},
24 {"ot_ip", test_ip}, 24 {"ot_ip", test_ip},
25 {"ot_socket", test_socket}, 25 {"ot_socket", test_socket},
26 {"ot_mutex", test_mutex},
26 {"ot_accesslist", test_accesslist}, 27 {"ot_accesslist", test_accesslist},
27 {NULL, NULL}}; 28 {NULL, NULL}};
28 29
diff --git a/tests/stubs.c b/tests/stubs.c
index ce93071..09a7312 100644
--- a/tests/stubs.c
+++ b/tests/stubs.c
@@ -18,3 +18,12 @@ void free_peerlist(ot_peerlist *peer_list) { (void)peer_list; }
18 neither of which any test drives. */ 18 neither of which any test drives. */
19time_t g_now_seconds; 19time_t g_now_seconds;
20volatile int g_opentracker_running; 20volatile int g_opentracker_running;
21
22/* ot_mutex.c wakes the main loop through the self pipe when a result is
23 ready. The queue tests never get that far. */
24int g_self_pipe[2] = {-1, -1};
25long io_trywrite(long d, const char *buf, long len) {
26 (void)d;
27 (void)buf;
28 return len;
29}
diff --git a/tests/test.h b/tests/test.h
index d79c4d2..9677524 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -86,5 +86,6 @@ void test_scan(void);
86void test_buf(void); 86void test_buf(void);
87void test_ip(void); 87void test_ip(void);
88void test_socket(void); 88void test_socket(void);
89void test_mutex(void);
89 90
90#endif 91#endif
diff --git a/trackerlogic.c b/trackerlogic.c
index 52c8c18..0fa7bfb 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -550,7 +550,7 @@ void trackerlogic_add_random_torrents(size_t amount) {
550} 550}
551#endif 551#endif
552 552
553void exerr(char *message) { 553void exerr(const char *message) {
554 fprintf(stderr, "%s\n", message); 554 fprintf(stderr, "%s\n", message);
555 exit(111); 555 exit(111);
556} 556}
diff --git a/trackerlogic.h b/trackerlogic.h
index aa10a54..42018c3 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -181,7 +181,7 @@ struct ot_workstruct {
181 181
182void trackerlogic_init(void); 182void trackerlogic_init(void);
183void trackerlogic_deinit(void); 183void trackerlogic_deinit(void);
184void exerr(char *message); 184void exerr(const char *message);
185 185
186/* add_peer_to_torrent does only release the torrent bucket if from_sync is set, 186/* add_peer_to_torrent does only release the torrent bucket if from_sync is set,
187 otherwise it is released in return_peers_for_torrent */ 187 otherwise it is released in return_peers_for_torrent */