Re: bump time_t/other type fixes to spamd
Speaking of spamd, I've been running the following diff for five months or so. It removes the use of time_t in the greylist db file and provides backwards compat for 32-bit times. - todd Index: usr.sbin/spamdb/Makefile === RCS file: /home/cvs/openbsd/src/usr.sbin/spamdb/Makefile,v retrieving revision 1.3 diff -u -p -u -r1.3 Makefile --- usr.sbin/spamdb/Makefile24 May 2005 22:23:05 - 1.3 +++ usr.sbin/spamdb/Makefile22 Apr 2013 20:03:45 - @@ -1,9 +1,11 @@ # $OpenBSD: Makefile,v 1.3 2005/05/24 22:23:05 millert Exp $ PROG= spamdb -SRCS= spamdb.c +SRCS= spamdb.c gdcopy.c MAN= spamdb.8 CFLAGS+= -Wall -Wstrict-prototypes -I${.CURDIR}/../../libexec/spamd + +.PATH: ${.CURDIR}/../../libexec/spamd .include bsd.prog.mk Index: usr.sbin/spamdb/spamdb.c === RCS file: /home/cvs/openbsd/src/usr.sbin/spamdb/spamdb.c,v retrieving revision 1.26 diff -u -p -u -r1.26 spamdb.c --- usr.sbin/spamdb/spamdb.c22 Apr 2013 19:49:36 - 1.26 +++ usr.sbin/spamdb/spamdb.c22 Apr 2013 20:03:45 - @@ -129,12 +129,11 @@ dbupdate(DB *db, char *ip, int add, int goto bad; } } else { - if (dbd.size != sizeof(gd)) { + if (gdcopyin(dbd, gd) == -1) { /* whatever this is, it doesn't belong */ db-del(db, dbk, 0); goto bad; } - memcpy(gd, dbd.data, sizeof(gd)); gd.pcount++; switch (type) { case WHITE: @@ -185,11 +184,10 @@ dblist(DB *db) r = db-seq(db, dbk, dbd, R_NEXT)) { char *a, *cp; - if ((dbk.size 1) || dbd.size != sizeof(struct gdata)) { + if ((dbk.size 1) || gdcopyin(dbd, gd) == -1) { db-close(db); errx(1, bogus size db entry - bad db file?); } - memcpy(gd, dbd.data, sizeof(gd)); a = malloc(dbk.size + 1); if (a == NULL) err(1, malloc); Index: libexec/spamd/Makefile === RCS file: /home/cvs/openbsd/src/libexec/spamd/Makefile,v retrieving revision 1.9 diff -u -p -u -r1.9 Makefile --- libexec/spamd/Makefile 4 Mar 2007 03:19:41 - 1.9 +++ libexec/spamd/Makefile 22 Apr 2013 20:03:45 - @@ -1,7 +1,7 @@ # $OpenBSD: Makefile,v 1.9 2007/03/04 03:19:41 beck Exp $ PROG= spamd -SRCS= spamd.c sdl.c grey.c sync.c +SRCS= spamd.c sdl.c gdcopy.c grey.c sync.c MAN= spamd.8 CFLAGS+= -Wall -Wstrict-prototypes Index: libexec/spamd/gdcopy.c === RCS file: libexec/spamd/gdcopy.c diff -N libexec/spamd/gdcopy.c --- /dev/null 1 Jan 1970 00:00:00 - +++ libexec/spamd/gdcopy.c 22 Apr 2013 20:03:45 - @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013 Todd C. Miller todd.mil...@courtesan.com + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include sys/types.h +#include db.h +#include stdio.h +#include stdlib.h +#include string.h +#include time.h + +#include grey.h + +/* Fill in struct gdata from DBT, converting from obsolete format as needed. */ +int +gdcopyin(const void *v, struct gdata *gd) +{ + const DBT *dbd = v; + int rc = 0; + + if (dbd-size == sizeof(struct gdata)) { + /* Current grey data format. */ + memcpy(gd, dbd-data, sizeof(struct gdata)); + } else if (dbd-size == sizeof(struct ogdata)) { + /* Backwards compat for obsolete grey data format. */ + struct ogdata ogd; + memcpy(ogd, dbd-data, sizeof(struct ogdata)); + gd-first = ogd.first; + gd-pass = ogd.pass; + gd-expire = ogd.expire; + gd-bcount = ogd.bcount; + gd-pcount = ogd.pcount; + } else { + /* Unsupported grey data format. */ + rc = -1; + } +
Re: bump time_t/other type fixes to spamd
I think this would be the way to go. On Wed, Aug 21, 2013 at 9:14 AM, Todd C. Miller todd.mil...@courtesan.com wrote: Speaking of spamd, I've been running the following diff for five months or so. It removes the use of time_t in the greylist db file and provides backwards compat for 32-bit times. - todd Index: usr.sbin/spamdb/Makefile === RCS file: /home/cvs/openbsd/src/usr.sbin/spamdb/Makefile,v retrieving revision 1.3 diff -u -p -u -r1.3 Makefile --- usr.sbin/spamdb/Makefile24 May 2005 22:23:05 - 1.3 +++ usr.sbin/spamdb/Makefile22 Apr 2013 20:03:45 - @@ -1,9 +1,11 @@ # $OpenBSD: Makefile,v 1.3 2005/05/24 22:23:05 millert Exp $ PROG= spamdb -SRCS= spamdb.c +SRCS= spamdb.c gdcopy.c MAN= spamdb.8 CFLAGS+= -Wall -Wstrict-prototypes -I${.CURDIR}/../../libexec/spamd + +.PATH: ${.CURDIR}/../../libexec/spamd .include bsd.prog.mk Index: usr.sbin/spamdb/spamdb.c === RCS file: /home/cvs/openbsd/src/usr.sbin/spamdb/spamdb.c,v retrieving revision 1.26 diff -u -p -u -r1.26 spamdb.c --- usr.sbin/spamdb/spamdb.c22 Apr 2013 19:49:36 - 1.26 +++ usr.sbin/spamdb/spamdb.c22 Apr 2013 20:03:45 - @@ -129,12 +129,11 @@ dbupdate(DB *db, char *ip, int add, int goto bad; } } else { - if (dbd.size != sizeof(gd)) { + if (gdcopyin(dbd, gd) == -1) { /* whatever this is, it doesn't belong */ db-del(db, dbk, 0); goto bad; } - memcpy(gd, dbd.data, sizeof(gd)); gd.pcount++; switch (type) { case WHITE: @@ -185,11 +184,10 @@ dblist(DB *db) r = db-seq(db, dbk, dbd, R_NEXT)) { char *a, *cp; - if ((dbk.size 1) || dbd.size != sizeof(struct gdata)) { + if ((dbk.size 1) || gdcopyin(dbd, gd) == -1) { db-close(db); errx(1, bogus size db entry - bad db file?); } - memcpy(gd, dbd.data, sizeof(gd)); a = malloc(dbk.size + 1); if (a == NULL) err(1, malloc); Index: libexec/spamd/Makefile === RCS file: /home/cvs/openbsd/src/libexec/spamd/Makefile,v retrieving revision 1.9 diff -u -p -u -r1.9 Makefile --- libexec/spamd/Makefile 4 Mar 2007 03:19:41 - 1.9 +++ libexec/spamd/Makefile 22 Apr 2013 20:03:45 - @@ -1,7 +1,7 @@ # $OpenBSD: Makefile,v 1.9 2007/03/04 03:19:41 beck Exp $ PROG= spamd -SRCS= spamd.c sdl.c grey.c sync.c +SRCS= spamd.c sdl.c gdcopy.c grey.c sync.c MAN= spamd.8 CFLAGS+= -Wall -Wstrict-prototypes Index: libexec/spamd/gdcopy.c === RCS file: libexec/spamd/gdcopy.c diff -N libexec/spamd/gdcopy.c --- /dev/null 1 Jan 1970 00:00:00 - +++ libexec/spamd/gdcopy.c 22 Apr 2013 20:03:45 - @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013 Todd C. Miller todd.mil...@courtesan.com + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include sys/types.h +#include db.h +#include stdio.h +#include stdlib.h +#include string.h +#include time.h + +#include grey.h + +/* Fill in struct gdata from DBT, converting from obsolete format as needed. */ +int +gdcopyin(const void *v, struct gdata *gd) +{ + const DBT *dbd = v; + int rc = 0; + + if (dbd-size == sizeof(struct gdata)) { + /* Current grey data format. */ + memcpy(gd, dbd-data, sizeof(struct gdata)); + } else if (dbd-size == sizeof(struct ogdata)) { + /* Backwards compat for obsolete grey data format. */ + struct ogdata ogd; + memcpy(ogd, dbd-data, sizeof(struct ogdata)); + gd-first = ogd.first; + gd-pass = ogd.pass;
Re: bump time_t/other type fixes to spamd
On Tue, 20 Aug 2013 20:36:38 -0700, William Orr wrote: Theo pointed out that it would be better to change whitecount to an int, so as to match the call to configure_pf(). Since trapcount is logically similar, and uses the same iterator variable in freeaddrlists(), I changed that to an int as well. This still includes the sscanf time_t fix. That looks fine to me. - todd
Re: bump time_t/other type fixes to spamd
William Orr mailto:w...@worrbase.com August 20, 2013 7:40 PM Bump Theo pointed out that it would be better to change whitecount to an int, so as to match the call to configure_pf(). Since trapcount is logically similar, and uses the same iterator variable in freeaddrlists(), I changed that to an int as well. This still includes the sscanf time_t fix. Ok ? Index: libexec/spamd/grey.c === RCS file: /cvs/src/libexec/spamd/grey.c,v retrieving revision 1.52 diff -u -b -w -p -r1.52 grey.c --- libexec/spamd/grey.c2 Oct 2012 15:26:17 -1.52 +++ libexec/spamd/grey.c21 Aug 2013 03:31:03 - @@ -61,8 +61,8 @@ int server_lookup4(struct sockaddr_in *, int server_lookup6(struct sockaddr_in6 *, struct sockaddr_in6 *, struct sockaddr_in6 *); -size_t whitecount, whitealloc; -size_t trapcount, trapalloc; +int whitecount, whitealloc; +int trapcount, trapalloc; char **whitelist; char **traplist; @@ -122,9 +122,9 @@ sig_term_chld(int sig) * host hits. */ void -configure_spamd(char **addrs, size_t count, FILE *sdc) +configure_spamd(char **addrs, int count, FILE *sdc) { -size_t i; +int i; fprintf(sdc, %s;, traplist_name); if (count != 0) { Index: libexec/spamd/spamd.c === RCS file: /cvs/src/libexec/spamd/spamd.c,v retrieving revision 1.112 diff -u -b -w -p -r1.112 spamd.c --- libexec/spamd/spamd.c19 Jun 2012 17:43:40 -1.112 +++ libexec/spamd/spamd.c21 Aug 2013 03:31:03 - @@ -265,7 +265,7 @@ void parse_configs(void) { char *start, *end; -int i; +size_t i; if (cbu == cbs) { char *tmp; @@ -371,7 +371,7 @@ append_error_string(struct con *cp, size char *c = cp-obuf + off; char *s = fmt; size_t len = cp-osize - off; -int i = 0; +size_t i = 0; if (off == 0) lastcont = 0; @@ -1114,7 +1114,7 @@ main(int argc, char *argv[]) greylist = 0; break; case 'G': -if (sscanf(optarg, %d:%d:%d, passtime, greyexp, +if (sscanf(optarg, %lld:%lld:%lld, passtime, greyexp, whiteexp) != 3) usage(); /* convert to seconds from minutes */