summaryrefslogtreecommitdiff
path: root/usr.bin/cal/cal.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-08-24 05:19:42 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-08-24 05:19:42 +0000
commit6b59875fe4a6cbb3757cee9f00d35c312f5ca4c1 (patch)
tree8ed970a1f5a8a2fd6054f69d1d43aaaef41efa28 /usr.bin/cal/cal.c
parente43eff62dc2370451bf18d1e2f3ee90b31f35393 (diff)
range check months 1-12; ok tedu millert others
Diffstat (limited to 'usr.bin/cal/cal.c')
-rw-r--r--usr.bin/cal/cal.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/usr.bin/cal/cal.c b/usr.bin/cal/cal.c
index e713137dd48..e4edcededbb 100644
--- a/usr.bin/cal/cal.c
+++ b/usr.bin/cal/cal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cal.c,v 1.14 2005/07/06 06:45:58 deraadt Exp $ */
+/* $OpenBSD: cal.c,v 1.15 2005/08/24 05:19:41 deraadt Exp $ */
/* $NetBSD: cal.c,v 1.6 1995/03/26 03:10:24 glass Exp $ */
/*
@@ -40,7 +40,7 @@ static const char copyright[] =
#if 0
static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94";
#else
-static const char rcsid[] = "$OpenBSD: cal.c,v 1.14 2005/07/06 06:45:58 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: cal.c,v 1.15 2005/08/24 05:19:41 deraadt Exp $";
#endif
#endif /* not lint */
@@ -429,16 +429,18 @@ usage(void)
int
parsemonth(const char *s)
{
- int v;
- char *cp;
struct tm tm;
+ char *cp;
+ int v;
v = (int)strtol(s, &cp, 10);
if (cp != s)
- return (v);
- if (strptime(s, "%B", &tm) != NULL)
- return (tm.tm_mon + 1);
- if (strptime(s, "%b", &tm) != NULL)
- return (tm.tm_mon + 1);
- return (0);
+ ;
+ else if (strptime(s, "%B", &tm) != NULL)
+ v = tm.tm_mon + 1;
+ else if (strptime(s, "%b", &tm) != NULL)
+ v = tm.tm_mon + 1;
+ if (v <= 0 || v > 12)
+ errx(1, "illegal month value: use 1-12");
+ return (v);
}