coverity: Fix a small logging bug (only log app name/ver if it's present)
Removed a lot of #ifdefs by using static username/version/addr vars always.
This commit is contained in:
parent
6cbf13b4e6
commit
4622369bb7
32
src/accept.c
32
src/accept.c
|
|
@ -454,36 +454,24 @@ static void peerip_clients_config(void)
|
|||
inbound_connects_account(3, c->udpclient->portaccount); /* "3" = udp, not listening.. */
|
||||
|
||||
/* set up peer serverid to username */
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->username = hstrdup(pe->serverid);
|
||||
#else
|
||||
strncpy(c->username, pe->serverid, sizeof(c->username));
|
||||
c->username[sizeof(c->username)-1] = 0;
|
||||
#endif
|
||||
c->username_len = strlen(c->username);
|
||||
|
||||
/* convert client address to string */
|
||||
s = strsockaddr( &c->udpaddr.sa, c->udpaddrlen );
|
||||
|
||||
/* text format of client's IP address + port */
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_rem = s;
|
||||
#else
|
||||
strncpy(c->addr_rem, s, sizeof(c->addr_rem));
|
||||
c->addr_rem[sizeof(c->addr_rem)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
/* hex format of client's IP address + port */
|
||||
s = hexsockaddr( &c->udpaddr.sa, c->udpaddrlen );
|
||||
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_hex = s;
|
||||
#else
|
||||
strncpy(c->addr_hex, s, sizeof(c->addr_hex));
|
||||
c->addr_hex[sizeof(c->addr_hex)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
/* text format of servers' connected IP address + port */
|
||||
addr_len = sizeof(sa);
|
||||
|
|
@ -494,13 +482,9 @@ static void peerip_clients_config(void)
|
|||
hlog(LOG_ERR, "Peer config: getsockname on udpclient->fd failed: %s", strerror(errno));
|
||||
s = hstrdup( "um" ); /* Server's bound IP address.. TODO: what? */
|
||||
}
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_loc = s;
|
||||
#else
|
||||
strncpy(c->addr_loc, s, sizeof(c->addr_loc));
|
||||
c->addr_loc[sizeof(c->addr_loc)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
/* pass the client to the first worker thread */
|
||||
if (pass_client_to_worker(worker_threads, c)) {
|
||||
|
|
@ -650,23 +634,15 @@ struct client_t *accept_client_for_listener(struct listen_t *l, int fd, char *ad
|
|||
inbound_connects_account(1, c->portaccount); /* account all ports + port-specifics */
|
||||
|
||||
/* text format of client's IP address + port */
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_rem = addr_s;
|
||||
#else
|
||||
strncpy(c->addr_rem, addr_s, sizeof(c->addr_rem));
|
||||
c->addr_rem[sizeof(c->addr_rem)-1] = 0;
|
||||
hfree(addr_s);
|
||||
#endif
|
||||
|
||||
/* hex format of client's IP address + port */
|
||||
s = hexsockaddr( &sa->sa, addr_len );
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_hex = s;
|
||||
#else
|
||||
strncpy(c->addr_hex, s, sizeof(c->addr_hex));
|
||||
c->addr_hex[sizeof(c->addr_hex)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
/* text format of servers' connected IP address + port */
|
||||
if (getsockname(fd, &sa_loc.sa, &addr_len_loc) == 0) { /* Fails very rarely.. */
|
||||
|
|
@ -678,13 +654,9 @@ struct client_t *accept_client_for_listener(struct listen_t *l, int fd, char *ad
|
|||
s = hstrdup( l->addr_s ); /* Server's bound IP address */
|
||||
hlog(LOG_ERR, "accept_client_for_listener: getsockname for client %s failed: %s (using '%s' instead)", c->addr_rem, strerror(errno), s);
|
||||
}
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_loc = s;
|
||||
#else
|
||||
strncpy(c->addr_loc, s, sizeof(c->addr_loc));
|
||||
c->addr_loc[sizeof(c->addr_loc)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
/* apply predefined filters */
|
||||
for (i = 0; i < (sizeof(l->filters)/sizeof(l->filters[0])); ++i) {
|
||||
|
|
@ -1087,12 +1059,8 @@ static int accept_liveupgrade_single(cJSON *client, int *rxerr_map, int rxerr_ma
|
|||
if (strcmp(state->valuestring, "connected") == 0) {
|
||||
c->state = CSTATE_CONNECTED;
|
||||
c->handler = &incoming_handler;
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->username = hstrdup(username->valuestring);
|
||||
#else
|
||||
strncpy(c->username, username->valuestring, sizeof(c->username));
|
||||
c->username[sizeof(c->username)-1] = 0;
|
||||
#endif
|
||||
c->username_len = strlen(c->username);
|
||||
} else if (strcmp(state->valuestring, "login") == 0) {
|
||||
c->state = CSTATE_LOGIN;
|
||||
|
|
|
|||
|
|
@ -210,22 +210,14 @@ int pseudoclient_push_packet(struct worker_t *worker, struct client_t *pseudocli
|
|||
/* fill the user's information in the pseudoclient's structure
|
||||
* for the q construct handler's viewing pleasure
|
||||
*/
|
||||
#ifdef FIXED_IOBUFS
|
||||
strncpy(pseudoclient->username, username, sizeof(pseudoclient->username));
|
||||
pseudoclient->username[sizeof(pseudoclient->username)-1] = 0;
|
||||
#else
|
||||
pseudoclient->username = username;
|
||||
#endif
|
||||
pseudoclient->username_len = strlen(pseudoclient->username);
|
||||
|
||||
/* ok, try to digest the packet */
|
||||
e = incoming_parse(worker, pseudoclient, packet, packet_len);
|
||||
|
||||
#ifdef FIXED_IOBUFS
|
||||
pseudoclient->username[0] = 0;
|
||||
#else
|
||||
pseudoclient->username = NULL;
|
||||
#endif
|
||||
pseudoclient->username_len = 0;
|
||||
|
||||
if (e < 0)
|
||||
|
|
|
|||
12
src/login.c
12
src/login.c
|
|
@ -142,20 +142,12 @@ void login_set_app_name(struct client_t *c, const char *app_name, const char *ap
|
|||
{
|
||||
int i;
|
||||
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->app_name = hstrdup(app_name);
|
||||
#else
|
||||
strncpy(c->app_name, app_name, sizeof(c->app_name));
|
||||
c->app_name[sizeof(c->app_name)-1] = 0;
|
||||
#endif
|
||||
sanitize_ascii_string(c->app_name);
|
||||
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->app_version = hstrdup(app_ver);
|
||||
#else
|
||||
strncpy(c->app_version, app_ver, sizeof(c->app_version));
|
||||
c->app_version[sizeof(c->app_version)-1] = 0;
|
||||
#endif
|
||||
sanitize_ascii_string(c->app_version);
|
||||
|
||||
/* check the application name against a static list of broken apps */
|
||||
|
|
@ -237,12 +229,8 @@ int login_handler(struct worker_t *self, struct client_t *c, int l4proto, char *
|
|||
goto failed_login;
|
||||
}
|
||||
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->username = hstrdup(username);
|
||||
#else
|
||||
strncpy(c->username, username, sizeof(c->username));
|
||||
c->username[sizeof(c->username)-1] = 0;
|
||||
#endif
|
||||
c->username_len = strlen(c->username);
|
||||
|
||||
/* check the username against a static list of disallowed usernames */
|
||||
|
|
|
|||
32
src/uplink.c
32
src/uplink.c
|
|
@ -192,14 +192,8 @@ int uplink_logresp_handler(struct worker_t *self, struct client_t *c, int l4prot
|
|||
/* todo: validate server callsign with the q valid path algorithm */
|
||||
|
||||
/* store the remote server's callsign as the "client username" */
|
||||
#ifndef FIXED_IOBUFS
|
||||
if (c->username)
|
||||
hfree(c->username);
|
||||
c->username = hstrdup(argv[5]);
|
||||
#else
|
||||
strncpy(c->username, argv[5], sizeof(c->username));
|
||||
c->username[sizeof(c->username)-1] = 0;
|
||||
#endif
|
||||
|
||||
hlog(LOG_INFO, "%s: Uplink logged in to server %s", c->addr_rem, c->username);
|
||||
|
||||
|
|
@ -224,13 +218,8 @@ int uplink_login_handler(struct worker_t *self, struct client_t *c, int l4proto,
|
|||
int argc;
|
||||
char *argv[256];
|
||||
|
||||
#ifndef FIXED_IOBUFS
|
||||
if (!c->username)
|
||||
c->username = hstrdup("simulator");
|
||||
#else
|
||||
if (!*c->username)
|
||||
strcpy(c->username, "simulator");
|
||||
#endif
|
||||
|
||||
hlog(LOG_INFO, "%s: Uplink server software: \"%.*s\"", c->addr_rem, len, s);
|
||||
|
||||
|
|
@ -245,15 +234,10 @@ int uplink_login_handler(struct worker_t *self, struct client_t *c, int l4proto,
|
|||
}
|
||||
|
||||
if (argc >= 3) {
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->app_name = hstrdup(argv[1]);
|
||||
c->app_version = hstrdup(argv[2]);
|
||||
#else
|
||||
strncpy(c->app_name, argv[1], sizeof(c->app_name));
|
||||
c->app_name[sizeof(c->app_name)-1] = 0;
|
||||
strncpy(c->app_version, argv[2], sizeof(c->app_version));
|
||||
c->app_version[sizeof(c->app_version)-1] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO: The uplink login command here could maybe be improved to send a filter command.
|
||||
|
|
@ -498,12 +482,8 @@ int make_uplink(struct uplink_config_t *l)
|
|||
c->keepalive = tick;
|
||||
c->connect_time = tick;
|
||||
c->last_read = tick; /* not simulated time */
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->username = hstrdup(serverid);
|
||||
#else
|
||||
strncpy(c->username, serverid, sizeof(c->username));
|
||||
c->username[sizeof(c->username)-1] = 0;
|
||||
#endif
|
||||
c->username_len = strlen(c->username);
|
||||
|
||||
/* These peer/sock name calls can not fail -- or the socket closed
|
||||
|
|
@ -512,35 +492,23 @@ int make_uplink(struct uplink_config_t *l)
|
|||
addr_len = sizeof(sa);
|
||||
getpeername(fd, (struct sockaddr *)&sa, &addr_len);
|
||||
//s = strsockaddr( &sa.sa, addr_len ); /* server side address */
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_rem = addr_s;
|
||||
#else
|
||||
strncpy(c->addr_rem, addr_s, sizeof(c->addr_rem));
|
||||
c->addr_rem[sizeof(c->addr_rem)-1] = 0;
|
||||
hfree(addr_s);
|
||||
#endif
|
||||
|
||||
/* hex format of client's IP address + port */
|
||||
|
||||
char *s = hexsockaddr( &sa.sa, addr_len );
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_hex = s;
|
||||
#else
|
||||
strncpy(c->addr_hex, s, sizeof(c->addr_hex));
|
||||
c->addr_hex[sizeof(c->addr_hex)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
addr_len = sizeof(sa);
|
||||
getsockname(fd, (struct sockaddr *)&sa, &addr_len);
|
||||
s = strsockaddr( &sa.sa, addr_len ); /* client side address */
|
||||
#ifndef FIXED_IOBUFS
|
||||
c->addr_loc = s;
|
||||
#else
|
||||
strncpy(c->addr_loc, s, sizeof(c->addr_loc));
|
||||
c->addr_loc[sizeof(c->addr_loc)-1] = 0;
|
||||
hfree(s);
|
||||
#endif
|
||||
|
||||
hlog(LOG_INFO, "Uplink %s: %s: Connection established on fd %d using source address %s", l->name, c->addr_rem, c->fd, c->addr_loc);
|
||||
|
||||
|
|
|
|||
13
src/worker.c
13
src/worker.c
|
|
@ -396,11 +396,6 @@ void client_free(struct client_t *c)
|
|||
#ifndef FIXED_IOBUFS
|
||||
if (c->ibuf) hfree(c->ibuf);
|
||||
if (c->obuf) hfree(c->obuf);
|
||||
if (c->addr_rem) hfree(c->addr_rem);
|
||||
if (c->addr_loc) hfree(c->addr_loc);
|
||||
if (c->username) hfree(c->username);
|
||||
if (c->app_name) hfree(c->app_name);
|
||||
if (c->app_version) hfree(c->app_version);
|
||||
#endif
|
||||
|
||||
filter_free(c->posdefaultfilters);
|
||||
|
|
@ -710,10 +705,10 @@ void client_close(struct worker_t *self, struct client_t *c, int errnum)
|
|||
c->localaccount.rxdrops,
|
||||
c->fd,
|
||||
self->id,
|
||||
(c->app_name) ? " app " : "",
|
||||
(c->app_name) ? c->app_name : "",
|
||||
(c->app_version) ? " ver " : "",
|
||||
(c->app_version) ? c->app_version : ""
|
||||
(c->app_name[0]) ? " app " : "",
|
||||
(c->app_name[0]) ? c->app_name : "",
|
||||
(c->app_version[0]) ? " ver " : "",
|
||||
(c->app_version[0]) ? c->app_version : ""
|
||||
);
|
||||
|
||||
if (c->localaccount.rxdrops) {
|
||||
|
|
|
|||
14
src/worker.h
14
src/worker.h
|
|
@ -284,11 +284,7 @@ struct client_t {
|
|||
union sockaddr_u udpaddr; /* ready to use sockaddr data */
|
||||
|
||||
int fd;
|
||||
#ifndef FIXED_IOBUFS
|
||||
char *addr_rem; /* remote IP address in text format */
|
||||
char *addr_hex; /* remote IP address in hex format */
|
||||
char *addr_loc; /* local IP address in text format */
|
||||
#endif
|
||||
|
||||
int uplink_index; /* uplink array index */
|
||||
int portnum;
|
||||
int listener_id; /* which listener is this client connected to */
|
||||
|
|
@ -341,12 +337,6 @@ struct client_t {
|
|||
char failed_cmds; /* how many login commands have failed */
|
||||
char quirks_mode; /* is this a known buggy-and-unmaintained application on our blacklist */
|
||||
|
||||
#ifndef FIXED_IOBUFS
|
||||
char *username; /* The callsign */
|
||||
char *app_name; /* application name, from 'user' command */
|
||||
char *app_version; /* application version, from 'user' command */
|
||||
#endif
|
||||
|
||||
/* the current handler function for incoming lines */
|
||||
int (*handler) (struct worker_t *self, struct client_t *c, int l4proto, char *s, int len);
|
||||
|
||||
|
|
@ -376,7 +366,6 @@ struct client_t {
|
|||
//uint32_t last_pbuf_seqnum;
|
||||
//uint32_t last_pbuf_dupe_seqnum;
|
||||
|
||||
#ifdef FIXED_IOBUFS
|
||||
char username[16]; /* The callsign */
|
||||
char app_name[32]; /* application name, from 'user' command */
|
||||
char app_version[32]; /* application version, from 'user' command */
|
||||
|
|
@ -385,6 +374,7 @@ struct client_t {
|
|||
char addr_hex[36]; /* client IP address in hex format */
|
||||
char addr_loc[80]; /* server IP address in text format */
|
||||
|
||||
#ifdef FIXED_IOBUFS
|
||||
char ibuf[IBUF_SIZE];
|
||||
char obuf[OBUF_SIZE];
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue