Skip to content

Commit

Permalink
fix: clang -Weverything build
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Apr 10, 2024
1 parent f6f1fdf commit 6bfb70f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- CC: gcc
CFLAGS: -O2 -Wall -Wextra -Werror -Wno-unknown-pragmas -Wno-unused-parameter -fvisibility=hidden -fno-strict-aliasing
- CC: clang
CFLAGS: -O2 -Weverything -Werror -Wno-unknown-pragmas -Wno-unused-parameter -fvisibility=hidden -fno-strict-aliasing
CFLAGS: -O2 -Weverything -Werror -Wno-unknown-warning-option -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unsafe-buffer-usage -Wno-strict-prototypes -fvisibility=hidden -fno-strict-aliasing
CPPFLAGS:
- ""
- "-DMINIMALISTIC_BUILD"
Expand Down
3 changes: 2 additions & 1 deletion cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ void parse_options(int argc, char** argv, struct globals_t* g)
case 'b':
++g->nsockets;
if (g->nsockets > g->nalloc) {
char** tmp;
g->nalloc += 16;
char** tmp = realloc(g->bind_addresses, g->nalloc * sizeof(char*));
tmp = realloc(g->bind_addresses, g->nalloc * sizeof(char*));
check_alloc(tmp, "realloc");
g->bind_addresses = tmp;
}
Expand Down
4 changes: 3 additions & 1 deletion connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void new_connection(struct ev_loop* loop, struct ev_io* w, int revents)
int sock = accept(w->fd, &sa, &len);
#endif
if (sock != -1) {
struct connection_t* conn;

#ifndef _GNU_SOURCE
if (-1 == make_nonblocking(sock)) {
my_log(LOG_DAEMON | LOG_WARNING, "new_connection(): failed to make the accept()'ed socket non-blocking: %s", strerror(errno));
Expand All @@ -110,7 +112,7 @@ void new_connection(struct ev_loop* loop, struct ev_io* w, int revents)
}
#endif

struct connection_t* conn = calloc(1, sizeof(struct connection_t));
conn = calloc(1, sizeof(struct connection_t));
conn->loop = loop;
conn->state = NEW_CONN;
ev_io_init(&conn->io, connection_callback, sock, EV_READ | EV_WRITE);
Expand Down
16 changes: 10 additions & 6 deletions dfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,25 @@ static int do_auth(struct connection_t* conn, int mask)

uint16_t caps = load2(conn->buffer + 0x04 - 0x04);
uint16_t extcaps = load2(conn->buffer + 0x06 - 0x04);
const uint8_t* user;
const uint8_t* user_end;
uint64_t pwd_len = 0;
const uint8_t* pos;
const uint8_t* auth_plugin = NULL;
uint8_t* tmp;

if ((caps & CLIENT_PROTOCOL_41) == 0) {
/* We do not support the old HandshakeResponse320 yet */
return out_of_order(conn, mask);
}

const uint8_t* user = (conn->buffer + 0x24 - 0x04);
const uint8_t* user_end = memchr(user, 0, conn->size - 0x24 + 0x04);
user = (conn->buffer + 0x24 - 0x04);
user_end = memchr(user, 0, conn->size - 0x24 + 0x04);
if (user_end == NULL) {
return out_of_order(conn, mask);
}

uint64_t pwd_len = 0;
const uint8_t* pos = user_end + 1;
pos = user_end + 1;
/* const uint8_t* pwd_pos; */
if (extcaps & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA) {
size_t bytes;
Expand Down Expand Up @@ -200,7 +205,6 @@ static int do_auth(struct connection_t* conn, int mask)
pos = schema_end + 1;
}

const uint8_t* auth_plugin = NULL;
if (extcaps & CLIENT_PLUGIN_AUTH) {
const uint8_t* plugin_end = memchr(pos, 0, (size_t)(conn->buffer + conn->size - pos));
if (plugin_end == NULL) {
Expand All @@ -223,7 +227,7 @@ static int do_auth(struct connection_t* conn, int mask)

log_access_denied(conn, user, auth_plugin, pwd_len);

uint8_t* tmp = create_auth_failed(conn->sequence + 1, user, conn->host, pwd_len > 0);
tmp = create_auth_failed(conn->sequence + 1, user, conn->host, pwd_len > 0);
free(conn->buffer);
conn->buffer = tmp;
conn->state = SLEEPING;
Expand Down
7 changes: 3 additions & 4 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
void my_log(int priority, const char *format, ...)
{
va_list ap;
time_t now;
struct tm timeinfo;
char timestring[32];
va_start(ap, format);

#ifndef MINIMALISTIC_BUILD
if (globals.no_syslog) {
#endif
time_t now;
struct tm timeinfo;
char timestring[32];

time(&now);
localtime_r(&now, &timeinfo);
strftime(timestring, sizeof(timestring), "%Y-%m-%d %H:%M:%S", &timeinfo);
Expand Down
6 changes: 4 additions & 2 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ uint8_t* create_auth_failed(uint8_t seq, const uint8_t* user, const char* server
};

char buf[4096];
uint8_t* result;
uint16_t size;

int n = snprintf(buf, 4096, "Access denied for user '%.48s'@'%s' (using password: %s)", user, server, use_pwd ? "YES" : "NO");
assert(n > 0 && n < 4096);

uint8_t* result = calloc(1, sizeof(tpl) + (size_t)n);
uint16_t size = (uint16_t)(sizeof(tpl) + (size_t)n - 4);
result = calloc(1, sizeof(tpl) + (size_t)n);
size = (uint16_t)(sizeof(tpl) + (size_t)n - 4);
store2(result, size);
memcpy(result + sizeof(size), tpl + sizeof(size), sizeof(tpl) - sizeof(size));
memcpy(result + sizeof(tpl), buf, (size_t)n);
Expand Down

0 comments on commit 6bfb70f

Please sign in to comment.