1
0
forked from bip/bip

merge master

This commit is contained in:
Arnaud Cornet 2009-01-05 23:24:49 +01:00
commit 0600196102
7 changed files with 33 additions and 23 deletions

View File

@ -5,6 +5,7 @@
set -e set -e
aclocal aclocal
autoheader
autoconf autoconf
automake --add-missing --copy -Wall automake --add-missing --copy -Wall

View File

@ -3,6 +3,7 @@ AM_CONFIG_HEADER(src/config.h)
AM_INIT_AUTOMAKE(bip,0.8.0) AM_INIT_AUTOMAKE(bip,0.8.0)
AC_PROG_CC AC_PROG_CC
AC_PROG_INSTALL AC_PROG_INSTALL
AM_PROG_LEX AM_PROG_LEX
AC_PROG_YACC AC_PROG_YACC

View File

@ -37,14 +37,14 @@ void readpass(char *buffer, int buflen)
struct termios tt, ttback; struct termios tt, ttback;
memset(&ttback, 0, sizeof(ttback)); memset(&ttback, 0, sizeof(ttback));
if (tcgetattr(ttyfd, &ttback) < 0) { if (tcgetattr(ttyfd, &ttback) < 0) {
printf("tcgetattr failed: %s\n", strerror(errno)); fprintf(stderr, "tcgetattr failed: %s\n", strerror(errno));
exit(1); exit(1);
} }
memcpy(&tt, &ttback, sizeof(ttback)); memcpy(&tt, &ttback, sizeof(ttback));
tt.c_lflag &= ~(ICANON|ECHO); tt.c_lflag &= ~(ICANON|ECHO);
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) { if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) {
printf("tcsetattr failed: %s\n", strerror(errno)); fprintf(stderr, "tcsetattr failed: %s\n", strerror(errno));
exit(1); exit(1);
} }
@ -74,6 +74,7 @@ int main(void)
unsigned int seed; unsigned int seed;
readpass(str, 256); readpass(str, 256);
str[255] = 0;
// the time used to type the pass is entropy // the time used to type the pass is entropy
srand(time(NULL)); srand(time(NULL));

View File

@ -36,9 +36,7 @@ list_t *root_list;
struct tuple *tuple_i_new(int type, int i) struct tuple *tuple_i_new(int type, int i)
{ {
struct tuple *t; struct tuple *t;
t = malloc(sizeof(struct tuple)); t = bip_malloc(sizeof(struct tuple));
if (!t)
fatal("malloc");
t->type = type; t->type = type;
t->ndata = i; t->ndata = i;
t->tuple_type = TUPLE_INT; t->tuple_type = TUPLE_INT;
@ -48,9 +46,7 @@ struct tuple *tuple_i_new(int type, int i)
struct tuple *tuple_p_new(int type, void *p) struct tuple *tuple_p_new(int type, void *p)
{ {
struct tuple *t; struct tuple *t;
t = malloc(sizeof(struct tuple)); t = bip_malloc(sizeof(struct tuple));
if (!t)
fatal("malloc");
t->type = type; t->type = type;
t->pdata = p; t->pdata = p;
return t; return t;

View File

@ -897,8 +897,6 @@ static void create_socket(char *dsthostname, char *dstport, char *srchostname,
cn->connected = CONN_ERROR; cn->connected = CONN_ERROR;
cdata = (struct connecting_data *) cdata = (struct connecting_data *)
bip_malloc(sizeof(struct connecting_data)); bip_malloc(sizeof(struct connecting_data));
if (!cdata)
fatal("Out of memory.");
cdata->dst = cdata->src = cdata->cur = NULL; cdata->dst = cdata->src = cdata->cur = NULL;
err = getaddrinfo(dsthostname, dstport, &hint, &cdata->dst); err = getaddrinfo(dsthostname, dstport, &hint, &cdata->dst);

View File

@ -88,8 +88,7 @@ char *nick_from_ircmask(const char *mask)
char *ret; char *ret;
size_t len; size_t len;
if (!mask) assert(mask);
fatal("nick_from_ircmask");
while (*nick && *nick != '!') while (*nick && *nick != '!')
nick++; nick++;
@ -1273,9 +1272,10 @@ static int irc_join(struct link_server *server, struct line *line)
return ERR_PROTOCOL; return ERR_PROTOCOL;
if (!line->origin) if (!line->origin)
return ERR_PROTOCOL; return ERR_PROTOCOL;
s_nick = nick_from_ircmask(line->origin);
s_nick = nick_from_ircmask(line->origin);
hash_insert(&channel->ovmasks, s_nick, 0); hash_insert(&channel->ovmasks, s_nick, 0);
free(s_nick);
return OK_COPY; return OK_COPY;
} }
@ -1490,9 +1490,12 @@ static int irc_part(struct link_server *server, struct line *line)
if (!line->origin) if (!line->origin)
return ERR_PROTOCOL; return ERR_PROTOCOL;
s_nick = nick_from_ircmask(line->origin); s_nick = nick_from_ircmask(line->origin);
if (!hash_includes(&channel->ovmasks, s_nick)) if (!hash_includes(&channel->ovmasks, s_nick)) {
free(s_nick);
return ERR_PROTOCOL; return ERR_PROTOCOL;
}
hash_remove(&channel->ovmasks, s_nick); hash_remove(&channel->ovmasks, s_nick);
free(s_nick);
log_part(LINK(server)->log, line->origin, s_chan, log_part(LINK(server)->log, line->origin, s_chan,
irc_line_count(line) == 3 ? irc_line_count(line) == 3 ?
@ -2128,6 +2131,7 @@ connection_t *irc_server_connect(struct link *link)
if (conn->handle == -1) { if (conn->handle == -1) {
mylog(LOG_INFO, "Cannot connect."); mylog(LOG_INFO, "Cannot connect.");
connection_free(conn); connection_free(conn);
server_next(link);
return NULL; return NULL;
} }

View File

@ -18,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
@ -41,7 +42,11 @@ void memory_fatal(void)
void *bip_malloc(size_t size) void *bip_malloc(size_t size)
{ {
void *r = malloc(size); void *r;
assert(size < INT_MAX / 4);
r = malloc(size);
if (!r) if (!r)
memory_fatal(); memory_fatal();
return r; return r;
@ -57,7 +62,11 @@ void *bip_calloc(size_t nmemb, size_t size)
void *bip_realloc(void *ptr, size_t size) void *bip_realloc(void *ptr, size_t size)
{ {
void *r = realloc(ptr, size); void *r;
assert(size < INT_MAX / 4);
r = realloc(ptr, size);
if (size > 0 && r == NULL) if (size > 0 && r == NULL)
memory_fatal(); memory_fatal();
return r; return r;