diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 19:42:27 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 19:42:27 +0100 |
| commit | 5bc4c0663576fd99bb06068e6dfd624690865c89 (patch) | |
| tree | e1e90e6966abebf960ed9c9d4ed0937be22961ff | |
| parent | 33b095eb26ab8be3af48d8bd034262cd5ab03a04 (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-- | Makefile | 6 | ||||
| -rw-r--r-- | opentracker.c | 2 | ||||
| -rw-r--r-- | ot_accesslist.c | 8 | ||||
| -rw-r--r-- | ot_accesslist.h | 6 | ||||
| -rw-r--r-- | ot_config.c | 12 | ||||
| -rw-r--r-- | ot_config.h | 8 | ||||
| -rw-r--r-- | ot_http.c | 10 | ||||
| -rw-r--r-- | ot_http.h | 2 | ||||
| -rw-r--r-- | ot_stats.c | 2 | ||||
| -rw-r--r-- | proxy.c | 2 | ||||
| -rw-r--r-- | scan_urlencoded_query.h | 4 | ||||
| -rw-r--r-- | tests/runner.c | 1 | ||||
| -rw-r--r-- | tests/stubs.c | 9 | ||||
| -rw-r--r-- | tests/test.h | 1 | ||||
| -rw-r--r-- | trackerlogic.c | 2 | ||||
| -rw-r--r-- | trackerlogic.h | 2 |
16 files changed, 44 insertions, 33 deletions
| @@ -64,7 +64,7 @@ GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse H | |||
| 64 | OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage | 64 | OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage |
| 65 | OPTS_production=-O3 | 65 | OPTS_production=-O3 |
| 66 | 66 | ||
| 67 | CFLAGS+=-I$(LIBOWFAT_HEADERS) -DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra #-ansi -pedantic | 67 | CFLAGS+=-I$(LIBOWFAT_HEADERS) -DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic |
| 68 | LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread | 68 | LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread |
| 69 | 69 | ||
| 70 | BINARY =opentracker | 70 | BINARY =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. |
| 121 | TESTBIN=tests/runner | 121 | TESTBIN=tests/runner |
| 122 | TEST_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 | 122 | TEST_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 |
| 123 | TEST_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 | 123 | TEST_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 |
| 124 | TEST_HEADERS=tests/test.h $(HEADERS) | 124 | TEST_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 |
| 35 | char *g_accesslist_filename = NULL; | 35 | const char *g_accesslist_filename = NULL; |
| 36 | #ifdef WANT_DYNAMIC_ACCESSLIST | 36 | #ifdef WANT_DYNAMIC_ACCESSLIST |
| 37 | char *g_accesslist_pipe_add = NULL; | 37 | const char *g_accesslist_pipe_add = NULL; |
| 38 | char *g_accesslist_pipe_delete = NULL; | 38 | const char *g_accesslist_pipe_delete = NULL; |
| 39 | #endif | 39 | #endif |
| 40 | static pthread_mutex_t g_accesslist_mutex; | 40 | static 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 |
| 274 | static pthread_t thread_adder_id, thread_deleter_id; | 274 | static pthread_t thread_adder_id, thread_deleter_id; |
| 275 | static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic *adding_to, ot_accesslist *_Atomic *removing_from) { | 275 | static 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 */ |
| 24 | size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len); | 24 | size_t accesslist_parse_hashes(ot_hash *dest, size_t capacity, const char *buf, size_t len); |
| 25 | 25 | ||
| 26 | extern char *g_accesslist_filename; | 26 | extern const char *g_accesslist_filename; |
| 27 | #ifdef WANT_DYNAMIC_ACCESSLIST | 27 | #ifdef WANT_DYNAMIC_ACCESSLIST |
| 28 | extern char *g_accesslist_pipe_add; | 28 | extern const char *g_accesslist_pipe_add; |
| 29 | extern char *g_accesslist_pipe_delete; | 29 | extern 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 | ||
| 25 | char *g_redirecturl; | 25 | const char *g_redirecturl; |
| 26 | char *g_serverdir; | 26 | const char *g_serverdir; |
| 27 | char *g_serveruser; | 27 | const char *g_serveruser; |
| 28 | char *g_statefile; | 28 | const 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 | ||
| 125 | char *set_config_option(char **option, char *value) { | 125 | static 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 | ||
| 25 | extern char *g_redirecturl; | 25 | extern const char *g_redirecturl; |
| 26 | extern char *g_serverdir; | 26 | extern const char *g_serverdir; |
| 27 | extern char *g_serveruser; | 27 | extern const char *g_serveruser; |
| 28 | extern char *g_statefile; | 28 | extern 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. */ |
| 31 | void config_parse(int argc, char **argv); | 31 | void config_parse(int argc, char **argv); |
| @@ -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) |
| 40 | extern char *g_redirecturl; | 40 | extern const char *g_redirecturl; |
| 41 | 41 | ||
| 42 | char *g_stats_path; | 42 | const char *g_stats_path; |
| 43 | ssize_t g_stats_path_len; | 43 | ssize_t g_stats_path_len; |
| 44 | 44 | ||
| 45 | enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; | 45 | enum { 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) |
| 127 | ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) { | 127 | ssize_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) |
| 494 | static char *http_header(char *data, size_t byte_count, char *header) { | 494 | static 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) { |
| @@ -37,7 +37,7 @@ ssize_t http_handle_request(const int64_t s, struct ot_workstruct *ws); | |||
| 37 | ssize_t http_sendiovecdata(const int64_t s, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial); | 37 | ssize_t http_sendiovecdata(const int64_t s, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial); |
| 38 | ssize_t http_issue_error(const int64_t s, struct ot_workstruct *ws, int code); | 38 | ssize_t http_issue_error(const int64_t s, struct ot_workstruct *ws, int code); |
| 39 | 39 | ||
| 40 | extern char *g_stats_path; | 40 | extern const char *g_stats_path; |
| 41 | extern ssize_t g_stats_path_len; | 41 | extern ssize_t g_stats_path_len; |
| 42 | 42 | ||
| 43 | #endif | 43 | #endif |
| @@ -53,7 +53,7 @@ static unsigned long long ot_full_scrape_count; | |||
| 53 | static unsigned long long ot_full_scrape_request_count; | 53 | static unsigned long long ot_full_scrape_request_count; |
| 54 | static unsigned long long ot_full_scrape_size; | 54 | static unsigned long long ot_full_scrape_size; |
| 55 | static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; | 55 | static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; |
| 56 | static char *ot_failed_request_names[] = { | 56 | static 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"}; |
| 59 | static unsigned long long ot_renewed[OT_PEER_TIMEOUT]; | 59 | static unsigned long long ot_renewed[OT_PEER_TIMEOUT]; |
| @@ -72,7 +72,7 @@ static void *livesync_worker(void *args); | |||
| 72 | static void *streamsync_worker(void *args); | 72 | static void *streamsync_worker(void *args); |
| 73 | static void livesync_proxytell(uint8_t prefix, uint8_t *info_hash, uint8_t *peer); | 73 | static void livesync_proxytell(uint8_t prefix, uint8_t *info_hash, uint8_t *peer); |
| 74 | 74 | ||
| 75 | void exerr(char *message) { | 75 | void 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 | ||
| 13 | typedef struct { | 13 | typedef struct { |
| 14 | char *key; | 14 | const char *key; |
| 15 | int value; | 15 | int value; |
| 16 | } ot_keywords; | 16 | } ot_keywords; |
| 17 | 17 | ||
| 18 | typedef enum { | 18 | typedef 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. */ |
| 19 | time_t g_now_seconds; | 19 | time_t g_now_seconds; |
| 20 | volatile int g_opentracker_running; | 20 | volatile 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. */ | ||
| 24 | int g_self_pipe[2] = {-1, -1}; | ||
| 25 | long 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); | |||
| 86 | void test_buf(void); | 86 | void test_buf(void); |
| 87 | void test_ip(void); | 87 | void test_ip(void); |
| 88 | void test_socket(void); | 88 | void test_socket(void); |
| 89 | void 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 | ||
| 553 | void exerr(char *message) { | 553 | void 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 | ||
| 182 | void trackerlogic_init(void); | 182 | void trackerlogic_init(void); |
| 183 | void trackerlogic_deinit(void); | 183 | void trackerlogic_deinit(void); |
| 184 | void exerr(char *message); | 184 | void 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 */ |
