Project

General

Profile

Enhancement #750 » 0006-sanitize-trivial-fixes-and-casts-to-types-expected-b.patch

Loïc Gomez, 2022-01-10 19:27

View differences:

src/bip.c
if (strlen(hex) != 40)
fatal("Incorrect password format %s\n", hex);
md5 = bip_malloc(20);
md5 = bip_malloc((size_t) 20);
for (i = 0; i < 20; i++) {
sscanf(hex + 2 * i, "%02x", &buf);
md5[i] = buf;
......
f = fopen(conf_pid_file, "r");
if (f)
goto pid_is_there;
if (gethostname(hname, 511) == -1)
if (gethostname(hname, (size_t)511) == -1)
fatal("%s %s", "gethostname", strerror(errno));
hname[511] = 0;
snprintf(longpath, longpath_max - 1, "%s.%s.%ld", conf_pid_file, hname,
......
n->serverv = NULL;
n->serverc = 0;
} else {
n = bip_calloc(sizeof(struct network), 1);
n = bip_calloc(sizeof(struct network), (size_t)1);
hash_insert(&bip->networks, name, n);
}
......
case LEX_BACKLOG:
ci->backlog = t2->ndata;
break;
default:
conf_die(bip, "Unknown keyword in channel block (%d)",
t2->type);
return 0;
}
if (t2->tuple_type == TUPLE_STR && t2->pdata)
free(t2->pdata);
......
}
u = hash_get(&bip->users, name);
if (!u) {
u = bip_calloc(sizeof(struct bipuser), 1);
u = bip_calloc(sizeof(struct bipuser), (size_t) 1);
hash_insert(&bip->users, name, u);
hash_init(&u->connections, HASH_NOCASE);
u->admin = 0;
......
else
nick = LINK(ic)->prev_nick;
vsnprintf(str, 4095, fmt, ap);
vsnprintf(str, (size_t)4095, fmt, ap);
str[4095] = 0;
WRITE_LINE2(CONN(ic), P_IRCMASK, (LINK(ic)->user->bip_use_notice ?
"NOTICE" : "PRIVMSG"), nick, str);
src/bip_main.c
if (conf_log_system && conf_daemonize) {
if (conf_global_log_file && conf_global_log_file != stderr)
fclose(conf_global_log_file);
snprintf(buf, 4095, "%s/bip.log", conf_log_root);
snprintf(buf, (size_t) 4095, "%s/bip.log", conf_log_root);
FILE *f = fopen(buf, "a");
if (!f)
fatal("Can't open %s: %s", buf, strerror(errno));
......
pid = daemonize();
else
pid = getpid();
snprintf(buf, 29, "%ld\n", (long unsigned int)pid);
snprintf(buf, (size_t) 29, "%lu\n", (unsigned long int)pid);
write(fd, buf, strlen(buf));
close(fd);
src/connection.c
* Shitty: we might have written a partial line, so we hack the line...
* Callers of _write_socket muse provide a writable message
*/
// this might be the same
#if EWOULDBLOCK == EAGAIN
if (errno == EAGAIN || errno == EINPROGRESS) {
#else
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
#endif
memmove(message, message + tcount, size - tcount + 1);
return WRITE_KEEP;
}
......
char *incoming;
list_t *outgoing;
conn = (connection_t *)bip_calloc(sizeof(connection_t), 1);
incoming = (char *)bip_malloc(CONN_BUFFER_SIZE);
conn = (connection_t *)bip_calloc(sizeof(connection_t), (size_t)1);
incoming = (char *)bip_malloc((size_t)CONN_BUFFER_SIZE);
outgoing = list_new(NULL);
conn->anti_flood = anti_flood;
......
connection_t *conn;
char portbuf[20];
/* TODO: allow litteral service name in the function interface */
if (snprintf(portbuf, 20, "%d", port) >= 20)
if (snprintf(portbuf, (size_t)20, "%d", port) >= 20)
portbuf[19] = '\0';
/*
......
SSL_load_error_strings();
errbio = BIO_new_fp(conf_global_log_file, BIO_NOCLOSE);
ssl_cx_idx = SSL_get_ex_new_index(0, "bip connection_t",
ssl_cx_idx = SSL_get_ex_new_index((size_t)0, "bip connection_t",
NULL, NULL,NULL);
flags = O_RDONLY;
......
}
do {
ret = read(fd, buf, 1024);
ret = read(fd, buf, (size_t)1024);
if (ret <= 0) {
mylog(LOG_ERROR,"/dev/random: %s",
strerror(errno));
......
mylog(LOG_ERROR, "Can't open SSL certificate check store! Check path "
"and permissions.");
return conn;
default:
fatal("Unknown SSL cert check mode.");
}
switch (conn->ssl_check_mode) {
......
(void)ssl_client_certfile;
#endif
/* TODO: allow litteral service name in the function interface */
if (snprintf(dstportbuf, 20, "%d", dstport) >= 20)
if (snprintf(dstportbuf, (size_t)20, "%d", dstport) >= 20)
dstportbuf[19] = '\0';
if (srcport) {
if (snprintf(srcportbuf, 20, "%d", srcport) >= 20)
if (snprintf(srcportbuf, (size_t)20, "%d", srcport) >= 20)
srcportbuf[19] = '\0';
tmp = srcportbuf;
} else
......
return NULL;
}
ip = bip_malloc(65);
ip = bip_malloc((size_t)65);
switch (addr.sa_family) {
case AF_INET:
src/irc.c
struct channel *channel_new(const char *name)
{
struct channel *chan;
chan = bip_calloc(sizeof(struct channel), 1);
chan = bip_calloc(sizeof(struct channel), (size_t)1);
chan->name = bip_strdup(name);
hash_init(&chan->ovmasks, HASH_NOCASE);
return chan;
......
list_t *ret;
hash_iterator_t hi;
size_t len = 0;
char *str = bip_malloc(NAMESIZE + 1);
char *str = bip_malloc((size_t)(NAMESIZE + 1));
ret = list_new(NULL);
*str = 0;
......
if (len + strlen(nick) + 2 + (ovmask ? 1 : 0) >= NAMESIZE) {
list_add_last(ret, str);
str = bip_malloc(NAMESIZE + 1);
str = bip_malloc((size_t)(NAMESIZE + 1));
*str = 0;
len = 0;
}
......
list_iterator_t itocs;
for (list_it_init(&LINK(server)->on_connect_send, &itocs);
list_it_item(&itocs); list_it_next(&itocs)) {
ssize_t len = strlen(list_it_item(&itocs)) + 2;
size_t len = strlen(list_it_item(&itocs)) + 2;
char *str = bip_malloc(len + 1);
sprintf(str, "%s\r\n", (char *)list_it_item(&itocs));
write_line(CONN(server), str);
......
if (LINK(server)->ignore_server_capab &&
irc_line_elem_equals(line, i, "CAPAB"))
irc_line_drop(line, i);
else if (!strncmp(irc_line_elem(line, i), "CHANMODES=", 10))
else if (!strncmp(irc_line_elem(line, i), "CHANMODES=", (size_t)10))
server_set_chanmodes(server, irc_line_elem(line, i) + 10);
else if (!strncmp(irc_line_elem(line, i), "PREFIX=(", 8))
else if (!strncmp(irc_line_elem(line, i), "PREFIX=(", (size_t)8))
server_set_prefix(server, irc_line_elem(line, i) + 7);
}
}
......
static char *irc_timestamp(void)
{
char *ts = bip_malloc(21);
snprintf(ts, 20, "%ld", (long int)time(NULL));
char *ts = bip_malloc((size_t)23);
snprintf(ts, (size_t)22, "%ld", (long int)time(NULL));
return ts;
}
......
if (!newconn)
return NULL;
ircc = bip_calloc(sizeof(struct link_client), 1);
ircc = bip_calloc(sizeof(struct link_client), (size_t)1);
CONN(ircc) = newconn;
TYPE(ircc) = IRC_TYPE_LOGGING_CLIENT;
CONN(ircc)->user_data = ircc;
......
{
struct link_client *c;
c = bip_calloc(sizeof(struct link_client), 1);
c = bip_calloc(sizeof(struct link_client), (size_t)1);
list_init(&c->who_queue, list_ptr_cmp);
return c;
......
{
struct link_server *s;
s = bip_calloc(sizeof(struct link_server), 1);
s = bip_calloc(sizeof(struct link_server), (size_t)1);
TYPE(s) = IRC_TYPE_SERVER;
hash_init(&s->channels, HASH_NOCASE);
......
content = (char *)bip_malloc(stats.st_size + 1);
if (fread(content, 1, stats.st_size, f) !=
if (fread(content, (size_t)1, stats.st_size, f) !=
(size_t)stats.st_size) {
mylog(LOG_WARN, "Can't read %s fully",
bip->oidentdpath);
......
bipstart = strstr(content, BIP_OIDENTD_START);
if (bipstart != NULL) {
/* We have some config left, rewrite the file
* completely */
fseek(f, SEEK_SET, 0);
if (ftruncate(fileno(f), 0) == -1) {
// We have some config left, rewrite the file completely
fseek(f, (long)SEEK_SET, (int)0);
if (ftruncate(fileno(f), (off_t)0) == -1) {
mylog(LOG_DEBUG, "Can't reset %s size",
bip->oidentdpath);
free(content);
......
struct link *irc_link_new(void)
{
struct link *link;
link = bip_calloc(sizeof(struct link), 1);
link = bip_calloc(sizeof(struct link), (size_t)1);
link->l_server = NULL;
hash_init(&link->chan_infos, HASH_NOCASE);
......
modes = cur + 1;
} else {
// emptry string
dup = bip_calloc(1, sizeof(char));
dup = bip_calloc((size_t)1, sizeof(char));
}
mylog(LOG_DEBUGVERB, "[%s] Modes: '%s'", LINK(l)->name, dup);
array_push(&l->chanmodes, dup);
src/irc.h
int backlog;
};
#define chan_info_new() bip_calloc(sizeof(struct chan_info), 1)
#define chan_info_new() bip_calloc(sizeof(struct chan_info), (size_t)1)
struct link_server {
struct link_connection _link_c;
......
void irc_server_free(struct link_server *is);
struct client *client_new(void);
void irc_main(bip_t *);
int ischannel(char p);
void irc_client_close(struct link_client *);
void irc_client_free(struct link_client *);
struct link *irc_link_new(void);
src/line.h
void irc_line_init(struct line *l);
void _irc_line_deinit(struct line *l);
struct line *irc_line_new();
struct line *irc_line_new(void);
void irc_line_write(struct line *l, connection_t *c);
void irc_line_append(struct line *l, const char *s);
struct line *irc_line_new_from_string(char *str);
src/log.c
int slash_ok = 1;
while (*tmp == '/') {
if (slash_ok) {
strncpy(dir + count, "/", 2);
strncpy(dir + count, "/", (size_t)2);
count++;
slash_ok = 0;
}
......
char *dest = bip_strdup(destination);
strtolower(dest);
logfile = (char *)bip_malloc(MAX_PATH_LEN + 1);
logfile = (char *)bip_malloc((size_t)MAX_PATH_LEN + 1);
time(&s);
now = localtime(&s);
strftime(year, 5, "%Y", now);
strftime(day, 3, "%d", now);
strftime(month, 3, "%m", now);
strftime(hour, 3, "%H", now);
snprintf(logfile, MAX_PATH_LEN, "%s/%s", conf_log_root,
strftime(year, (size_t)5, "%Y", now);
strftime(day, (size_t)3, "%d", now);
strftime(month, (size_t)3, "%m", now);
strftime(hour, (size_t)3, "%H", now);
snprintf(logfile, (size_t)MAX_PATH_LEN, "%s/%s", conf_log_root,
conf_log_format);
replace_var(logfile, "%u", logdata->user->name, MAX_PATH_LEN);
replace_var(logfile, "%n", logdata->network, MAX_PATH_LEN);
......
return 0;
}
if (fseek(f, 0, SEEK_END) == -1) {
if (fseek(f, (long)0, SEEK_END) == -1) {
mylog(LOG_ERROR, "fseek(%s) %s", uniq_fname,
strerror(errno));
free(uniq_fname);
......
store = hash_get(&logdata->logfgs, destination);
if (!store) {
store = bip_calloc(sizeof(logstore_t), 1);
store = bip_calloc(sizeof(logstore_t), (size_t)1);
list_init(&store->file_group, NULL);
store->name = bip_strdup(destination);
store->skip_advance = 0;
......
void log_join(log_t *logdata, const char *ircmask, const char *channel)
{
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has joined %s", timestamp(), ircmask,
channel);
log_write(logdata, channel, logdata->buffer);
......
const char *message)
{
if (message)
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has left %s [%s]", timestamp(), ircmask,
channel, message);
else
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has left %s", timestamp(), ircmask,
channel);
log_write(logdata, channel, logdata->buffer);
......
void log_kick(log_t *logdata, const char *ircmask, const char *channel,
const char *who, const char *message)
{
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has been kicked by %s [%s]", timestamp(),
who, ircmask, message);
log_write(logdata, channel, logdata->buffer);
......
void log_quit(log_t *logdata, const char *ircmask, const char *channel,
const char *message)
{
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has quit [%s]", timestamp(), ircmask,
message);
log_write(logdata, channel, logdata->buffer);
......
}
free(oldnick);
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s is now known as %s",
timestamp(), ircmask, newnick);
log_write(logdata, channel, logdata->buffer);
......
if (*message == '+' || *message == '-')
real_message++;
if (strncmp(real_message, "\001ACTION ", 8) != 0)
if (strncmp(real_message, "\001ACTION ", (size_t)8) != 0)
return;
msg = bip_strdup(real_message);
*(msg + strlen(msg) - 1) = '\0';
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s %c * %s %s", timestamp(), dir,
from, msg + 8);
free(msg);
} else {
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s %c %s: %s", timestamp(), dir,
from, message);
}
......
void log_topic(log_t *logdata, const char *ircmask, const char *channel,
const char *message)
{
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s changed topic of %s to: %s", timestamp(),
ircmask, channel, message);
log_write(logdata, channel, logdata->buffer);
......
void log_init_topic(log_t *logdata, const char *channel, const char *message)
{
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Topic for %s: %s", timestamp(), channel,
message);
log_write(logdata, channel, logdata->buffer);
......
seconds = atoi(when);
time = localtime(&seconds);
timestr = (char *)bip_malloc(50 + 1);
timestr = (char *)bip_malloc((size_t)50 + 1);
timestr[0] = '\0';
if (time)
strftime(timestr, 50, "%A %d %B %Y, %H:%M:%S", time);
strftime(timestr, (size_t)50, "%A %d %B %Y, %H:%M:%S", time);
timestr[50] = '\0';
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Topic set by %s [%s]", timestamp(), who,
timestr);
free(timestr);
......
const char *modes, array_t *mode_args)
{
int i;
char *tmpbuf = bip_malloc(LOGLINE_MAXLEN + 1);
char *tmpbuf2 = bip_malloc(LOGLINE_MAXLEN + 1);
char *tmpbuf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
char *tmpbuf2 = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
char *tmp;
snprintf(tmpbuf, LOGLINE_MAXLEN, "%s -!- mode/%s [%s", timestamp(),
channel, modes);
snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN,
"%s -!- mode/%s [%s", timestamp(), channel, modes);
if (mode_args) {
for (i = 0; i < array_count(mode_args); i++) {
snprintf(tmpbuf2, LOGLINE_MAXLEN, "%s %s", tmpbuf,
snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s", tmpbuf,
(char *)array_get(mode_args, i));
tmp = tmpbuf;
tmpbuf = tmpbuf2;
......
}
}
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s] by %s", tmpbuf, ircmask);
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s",
tmpbuf, ircmask);
log_write(logdata, channel, logdata->buffer);
free(tmpbuf);
......
void log_disconnected(log_t *logdata)
{
hash_iterator_t hi;
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s -!- Disconnected"
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Disconnected"
" from server...", timestamp());
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
hash_it_next(&hi))
......
list_t *l = log_backlogs(logdata);
char *s;
snprintf(logdata->buffer, LOGLINE_MAXLEN,
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Ping timeout with server...", timestamp());
while ((s = list_remove_first(l))) {
log_write(logdata, s, logdata->buffer);
......
{
hash_iterator_t hi;
snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s -!- Connected to"
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Connected to"
" server...", timestamp());
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
hash_it_next(&hi)) {
......
lots = p - sots;
p++;
if (strncmp(p, "-!-", 3) == 0) {
if (strncmp(p, "-!-", (size_t)3) == 0) {
if (logdata->user->bl_msg_only)
return NULL;
else
......
}
} else {
//mylog(LOG_ERROR, "bread Seeking %s to %d", lf->filename, 0);
if (fseek(lf->file, 0, SEEK_SET)) {
if (fseek(lf->file, (long)0, SEEK_SET)) {
mylog(LOG_ERROR, "Can't seek in %s", lf->filename);
list_add_last(res, _log_wrap(store->name,
"Error seeking in logfile"));
......
}
}
buf = bip_malloc(LOGLINE_MAXLEN + 1);
buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
for(;;) {
if (!fgets(buf, LOGLINE_MAXLEN, lf->file)) {
if (ferror(lf->file)) {
......
char *buf;
size_t count;
buf = bip_malloc(LOGLINE_MAXLEN + 1);
count = snprintf(buf, LOGLINE_MAXLEN + 1,
buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
count = snprintf(buf, (size_t)LOGLINE_MAXLEN + 1,
":" P_IRCMASK " PRIVMSG %s :%s\r\n", dest, line);
if (count >= LOGLINE_MAXLEN + 1) {
mylog(LOG_DEBUG, "line too long");
......
size_t len;
static char tmpstr[LOGLINE_MAXLEN + 1];
strncpy(tmpstr, str, LOGLINE_MAXLEN);
strncpy(tmpstr, str, (size_t)LOGLINE_MAXLEN);
tmpstr[LOGLINE_MAXLEN] = 0;
if (store->memlog) {
......
len = strlen(tmpstr);
nbwrite = fwrite(tmpstr, sizeof(char), len, lf->file);
nbwrite += fwrite("\n", sizeof(char), 1, lf->file);
nbwrite += fwrite("\n", sizeof(char), (size_t)1, lf->file);
log_updatelast(lf);
if (nbwrite != len + 1)
mylog(LOG_ERROR, "Error writing to %s logfile", lf->filename);
......
{
log_t *logdata;
logdata = (log_t *)bip_calloc(sizeof(log_t), 1);
logdata = (log_t *)bip_calloc(sizeof(log_t), (size_t)1);
logdata->user = user;
logdata->network = bip_strdup(network);
hash_init(&logdata->logfgs, HASH_NOCASE);
logdata->buffer = (char *)bip_malloc(LOGLINE_MAXLEN + 1);
logdata->buffer = (char *)bip_malloc((size_t)LOGLINE_MAXLEN + 1);
logdata->buffer[LOGLINE_MAXLEN - 1] = 0; // debug
logdata->buffer[LOGLINE_MAXLEN] = 0;
logdata->connected = 0;
src/md5.c
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
md5_update( ctx, md5_padding, padn );
md5_update( ctx, msglen, 8 );
md5_update( ctx, msglen, (unsigned long)8 );
PUT_UINT32( ctx->state[0], digest, 0 );
PUT_UINT32( ctx->state[1], digest, 4 );
......
ptr[3] = seed & 0xff;
memcpy(ptr + 4, str, length - 4);
md5 = bip_malloc(16 + 4);
memcpy(md5, ptr, 4);
md5 = bip_malloc((size_t)16 + 4);
memcpy(md5, ptr, (size_t)4);
md5_starts(&ctx);
md5_update(&ctx, ptr, length);
md5_finish(&ctx, md5 + 4);
md5_starts(&ctx);
md5_update(&ctx, md5, 20);
md5_update(&ctx, md5, (unsigned long)20);
md5_finish(&ctx, md5 + 4);
free(ptr);
return md5;
src/util.c
{
fflush(conf_global_log_file);
#define OOMMSG "Out of memory.\n"
fwrite(OOMMSG, 1, strlen(OOMMSG), conf_global_log_file);
fwrite(OOMMSG, (size_t)1, strlen(OOMMSG), conf_global_log_file);
#undef OOMMSG
fflush(conf_global_log_file);
exit(28);
......
time(&tv);
tm = localtime(&tv);
strftime(ts, 20, "%d-%m-%Y %H:%M:%S", tm);
strftime(ts, (size_t)20, "%d-%m-%Y %H:%M:%S", tm);
return ts;
}
......
return "never";
tm = localtime(&s);
strftime(ts, 20, "%d-%m-%Y %H:%M:%S", tm);
strftime(ts, (size_t)20, "%d-%m-%Y %H:%M:%S", tm);
return ts;
}
(5-5/24)