diff --git a/Makefile b/Makefile index 507c3e9..05ca856 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ MAJOR=2 MINOR=1 CC?=gcc -CFLAGS?=-g -O2 -Wall -CFLAGS+=-I. -DVERSION=\"$(MAJOR).$(MINOR)\" +CFLAGS?=-g -O2 -Wall +CPPFLAGS?=-I. -DVERSION=\"$(MAJOR).$(MINOR)\" prefix?=/usr/local OBJS=\ cbtcommon/debug.o\ @@ -20,6 +20,9 @@ OBJS=\ all: cvsps +deps: + makedepend -Y -I. *.c cbtcommon/*.c + cvsps: $(OBJS) $(CC) -o cvsps $(OBJS) -lz @@ -33,3 +36,27 @@ clean: rm -f cvsps *.o cbtcommon/*.o core .PHONY: install clean +# DO NOT DELETE + +cache.o: ./cbtcommon/hash.h ./cbtcommon/list.h ./cbtcommon/inline.h +cache.o: ./cbtcommon/debug.h cache.h cvsps_types.h cvsps.h util.h +cap.o: ./cbtcommon/debug.h ./cbtcommon/inline.h ./cbtcommon/text_util.h cap.h +cap.o: cvs_direct.h +cvs_direct.o: ./cbtcommon/debug.h ./cbtcommon/inline.h +cvs_direct.o: ./cbtcommon/text_util.h ./cbtcommon/tcpsocket.h +cvs_direct.o: ./cbtcommon/sio.h cvs_direct.h util.h +cvsps.o: ./cbtcommon/hash.h ./cbtcommon/list.h ./cbtcommon/inline.h +cvsps.o: ./cbtcommon/list.h ./cbtcommon/text_util.h ./cbtcommon/debug.h +cvsps.o: ./cbtcommon/rcsid.h cache.h cvsps_types.h cvsps.h util.h stats.h +cvsps.o: cap.h cvs_direct.h list_sort.h +list_sort.o: list_sort.h ./cbtcommon/list.h +stats.o: ./cbtcommon/hash.h ./cbtcommon/list.h ./cbtcommon/inline.h +stats.o: cvsps_types.h cvsps.h +util.o: ./cbtcommon/debug.h ./cbtcommon/inline.h util.h +cbtcommon/debug.o: cbtcommon/debug.h ./cbtcommon/inline.h cbtcommon/rcsid.h +cbtcommon/hash.o: cbtcommon/debug.h ./cbtcommon/inline.h cbtcommon/hash.h +cbtcommon/hash.o: ./cbtcommon/list.h cbtcommon/rcsid.h +cbtcommon/sio.o: cbtcommon/sio.h cbtcommon/rcsid.h +cbtcommon/tcpsocket.o: cbtcommon/tcpsocket.h cbtcommon/debug.h +cbtcommon/tcpsocket.o: ./cbtcommon/inline.h cbtcommon/rcsid.h +cbtcommon/text_util.o: cbtcommon/text_util.h cbtcommon/rcsid.h diff --git a/cache.c b/cache.c index 4c51cf7..5f67a7c 100644 --- a/cache.c +++ b/cache.c @@ -108,10 +108,19 @@ time_t read_cache() int tag_flags = 0; char branchbuff[LOG_STR_MAX] = ""; int branch_add = 0; - char logbuff[LOG_STR_MAX] = ""; + int logbufflen = LOG_STR_MAX + 1; + char * logbuff = malloc(logbufflen); time_t cache_date = -1; int read_version; + if (logbuff == NULL) + { + debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in read_cache", logbufflen); + exit(1); + } + + logbuff[0] = 0; + if (!(fp = cache_open("r"))) goto out; @@ -299,8 +308,19 @@ time_t read_cache() else { /* Make sure we have enough in the buffer */ - if (strlen(logbuff)+strlen(buff)= LOG_STR_MAX) + { + logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX); + char * newlogbuff = realloc(logbuff, logbufflen); + if (newlogbuff == NULL) + { + debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in read_cache", logbufflen); + exit(1); + } + logbuff = newlogbuff; + } + strcat(logbuff, buff); } break; case CACHE_NEED_PS_MEMBERS: @@ -332,6 +352,7 @@ time_t read_cache() out_close: fclose(fp); out: + free(logbuff); return cache_date; } @@ -344,7 +365,7 @@ enum CR_BRANCH_POINT }; -static void parse_cache_revision(PatchSetMember * psm, const char * p_buff) +static void parse_cache_revision(PatchSetMember * psm, const char * buff) { /* The format used to generate is: * "file:%s; pre_rev:%s; post_rev:%s; dead:%d; branch_point:%d\n" @@ -354,35 +375,37 @@ static void parse_cache_revision(PatchSetMember * psm, const char * p_buff) char post[REV_STR_MAX]; int dead = 0; int bp = 0; - char buff[BUFSIZ]; int state = CR_FILENAME; - const char *s; - char * p = buff; - - strcpy(buff, p_buff); + const char *sep; + char * p; + char * c; - while ((s = strsep(&p, ";"))) + for (p = buff, sep = buff; /* just ensure sep is non-NULL */ + (sep != NULL) && (c = strchr(p, ':')); + p = sep + 1) { - char * c = strchr(s, ':'); - - if (!c) - { - debug(DEBUG_APPERROR, "invalid cache revision line '%s'|'%s'", p_buff, s); - exit(1); - } + size_t len; + sep = strchr(c, ';'); + c++; - *c++ = 0; + if (sep != NULL) + len = sep - c; + else /* last field in the cache line */ + len = strlen(c); switch(state) { case CR_FILENAME: - strcpy(filename, c); + memcpy(filename, c, len); + filename[len] = '\0'; break; case CR_PRE_REV: - strcpy(pre, c); + memcpy(pre, c, len); + pre[len] = '\0'; break; case CR_POST_REV: - strcpy(post, c); + memcpy(post, c, len); + post[len] = '\0'; break; case CR_DEAD: dead = atoi(c); diff --git a/cap.c b/cap.c index a6186f6..a1927df 100644 --- a/cap.c +++ b/cap.c @@ -121,11 +121,19 @@ int check_version_string(const char * str, int req_major, int req_minor, int req return 0; } + /* We might have encountered a FreeBSD system which + * has a mucked up version string of: + * Concurrent Versions System (CVS) '1.11.17'-FreeBSD (client/server) + * so re-test just in case + */ p += skip; if (sscanf(p, "%d.%d.%d", &major, &minor, &extra) != 3) { - debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: %s", str); - return 0; + if (sscanf(p, "'%d.%d.%d'", &major, &minor, &extra) != 3) + { + debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: %s", str); + return 0; + } } return (major > req_major || diff --git a/cbtcommon/tcpsocket.c b/cbtcommon/tcpsocket.c index 27cc13a..f31060e 100644 --- a/cbtcommon/tcpsocket.c +++ b/cbtcommon/tcpsocket.c @@ -185,20 +185,20 @@ tcp_connect(int sockfd, const char *rem_addr, unsigned short port) int convert_address(long *dest, const char *addr_str) { -#ifdef LINUX +#ifdef __linux__ struct in_addr ip; #endif int retval = 0; char errstr[256]; /* first try converting "numbers and dots" notation */ -#ifdef LINUX +#ifdef __linux__ if ( inet_aton(addr_str, &ip) ) { memcpy(dest, &ip.s_addr, sizeof(ip.s_addr)); } #else - if ( (*dest = inet_addr(addr_str)) != -1) + if ( (*dest = inet_addr(addr_str)) != INADDR_NONE) { /* nothing */ } diff --git a/cvsps.1 b/cvsps.1 index cea0faf..6cfdac6 100644 --- a/cvsps.1 +++ b/cvsps.1 @@ -83,7 +83,7 @@ some hacks which are not generally applicable. disable the use of rlog internally. Note: rlog is required for stable PatchSet numbering. Use with care. .TP -.B \-\-diffs\-opts