Check date_parse return values.
authorray <ray@openbsd.org>
Fri, 30 Jul 2010 21:47:18 +0000 (21:47 +0000)
committerray <ray@openbsd.org>
Fri, 30 Jul 2010 21:47:18 +0000 (21:47 +0000)
OK xsa

usr.bin/cvs/annotate.c
usr.bin/cvs/checkout.c
usr.bin/cvs/diff.c
usr.bin/cvs/getlog.c
usr.bin/cvs/update.c
usr.bin/rcs/ci.c
usr.bin/rcs/co.c
usr.bin/rcs/rlog.c

index ac63148..b5e391f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: annotate.c,v 1.61 2010/07/23 21:46:05 ray Exp $       */
+/*     $OpenBSD: annotate.c,v 1.62 2010/07/30 21:47:18 ray Exp $       */
 /*
  * Copyright (c) 2007 Tobias Stoeckmann <tobias@openbsd.org>
  * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -69,7 +69,8 @@ cvs_annotate(int argc, char **argv)
                switch (ch) {
                case 'D':
                        dateflag = optarg;
-                       cvs_specified_date = date_parse(dateflag);
+                       if ((cvs_specified_date = date_parse(dateflag)) == -1)
+                               fatal("invalid date: %s", dateflag);
                        break;
                case 'f':
                        force_head = 1;
index 1f6d362..3bd5672 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: checkout.c,v 1.166 2010/07/23 21:46:05 ray Exp $      */
+/*     $OpenBSD: checkout.c,v 1.167 2010/07/30 21:47:18 ray Exp $      */
 /*
  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
  *
@@ -95,7 +95,8 @@ cvs_checkout(int argc, char **argv)
                        exit(0);
                case 'D':
                        dateflag = optarg;
-                       cvs_specified_date = date_parse(dateflag);
+                       if ((cvs_specified_date = date_parse(dateflag)) == -1)
+                               fatal("invalid date: %s", dateflag);
                        reset_tag = 0;
                        break;
                case 'd':
index a9ee2ab..11762ba 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: diff.c,v 1.158 2010/07/28 21:19:30 nicm Exp $ */
+/*     $OpenBSD: diff.c,v 1.159 2010/07/30 21:47:18 ray Exp $  */
 /*
  * Copyright (c) 2008 Tobias Stoeckmann <tobias@openbsd.org>
  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
@@ -106,10 +106,12 @@ cvs_diff(int argc, char **argv)
                        break;
                case 'D':
                        if (date1 == -1 && rev1 == NULL) {
-                               date1 = date_parse(optarg);
+                               if ((date1 = date_parse(optarg)) == -1)
+                                       fatal("invalid date: %s", optarg);
                                dateflag1 = optarg;
                        } else if (date2 == -1 && rev2 == NULL) {
-                               date2 = date_parse(optarg);
+                               if ((date2 = date_parse(optarg)) == -1)
+                                       fatal("invalid date: %s", optarg);
                                dateflag2 = optarg;
                        } else {
                                fatal("no more than 2 revisions/dates can"
index 73917bc..0df3887 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: getlog.c,v 1.94 2010/07/23 21:46:05 ray Exp $ */
+/*     $OpenBSD: getlog.c,v 1.95 2010/07/30 21:47:18 ray Exp $ */
 /*
  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
@@ -232,9 +232,12 @@ cvs_log_local(struct cvs_file *cf)
 
        if (logrev != NULL)
                nrev = cvs_revision_select(cf->file_rcs, logrev);
-       else if (logdate != NULL)
-               nrev = date_select(cf->file_rcs, logdate);
-       else
+       else if (logdate != NULL) {
+               if ((nrev = date_select(cf->file_rcs, logdate)) == -1) {
+                       cvs_log(LP_ERR, "invalid date: %s", logdate);
+                       return;
+               }
+       } else
                nrev = cf->file_rcs->rf_ndelta;
 
        cvs_printf("\nRCS file: %s", cf->file_rpath);
@@ -452,7 +455,8 @@ date_select(RCSFILE *file, char *date)
 
                if (last == NULL) {
                        flags |= LDATE_SINGLE;
-                       firstdate = date_parse(first);
+                       if ((firstdate = date_parse(first)) == -1)
+                               return -1;
                        delim = '\0';
                        last = "\0";
                } else {
@@ -462,22 +466,26 @@ date_select(RCSFILE *file, char *date)
 
                if (delim == '>' && *last == '\0') {
                        flags |= LDATE_EARLIER;
-                       firstdate = date_parse(first);
+                       if ((firstdate = date_parse(first)) == -1)
+                               return -1;
                }
 
                if (delim == '>' && *first == '\0' && *last != '\0') {
                        flags |= LDATE_LATER;
-                       firstdate = date_parse(last);
+                       if ((firstdate = date_parse(last)) == -1)
+                               return -1;
                }
 
                if (delim == '<' && *last == '\0') {
                        flags |= LDATE_LATER;
-                       firstdate = date_parse(first);
+                       if ((firstdate = date_parse(first)) == -1)
+                               return -1;
                }
 
                if (delim == '<' && *first == '\0' && *last != '\0') {
                        flags |= LDATE_EARLIER;
-                       firstdate = date_parse(last);
+                       if ((firstdate = date_parse(last)) == -1)
+                               return -1;
                }
 
                if (*first != '\0' && *last != '\0') {
@@ -490,6 +498,8 @@ date_select(RCSFILE *file, char *date)
                                firstdate = date_parse(last);
                                lastdate = date_parse(first);
                        }
+                       if (firstdate == -1 || lastdate == -1)
+                               return -1;
                }
 
                TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list) {
index 5a0b2c7..4ff5fb8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: update.c,v 1.162 2010/07/23 21:46:05 ray Exp $        */
+/*     $OpenBSD: update.c,v 1.163 2010/07/30 21:47:18 ray Exp $        */
 /*
  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
  *
@@ -78,7 +78,8 @@ cvs_update(int argc, char **argv)
                        break;
                case 'D':
                        dateflag = optarg;
-                       cvs_specified_date = date_parse(dateflag);
+                       if ((cvs_specified_date = date_parse(dateflag)) == -1)
+                               fatal("invalid date: %s", dateflag);
                        reset_tag = 0;
                        break;
                case 'd':
@@ -592,7 +593,10 @@ update_join_file(struct cvs_file *cf)
 
        if ((p = strchr(jrev2, ':')) != NULL) {
                (*p++) = '\0';
-               cvs_specified_date = date_parse(p);
+               if ((cvs_specified_date = date_parse(p)) == -1) {
+                       cvs_printf("invalid date: %s", p);
+                       goto out;
+               }
        }
 
        rev2 = rcs_translate_tag(jrev2, cf->file_rcs);
@@ -601,7 +605,10 @@ update_join_file(struct cvs_file *cf)
        if (jrev1 != NULL) {
                if ((p = strchr(jrev1, ':')) != NULL) {
                        (*p++) = '\0';
-                       cvs_specified_date = date_parse(p);
+                       if ((cvs_specified_date = date_parse(p)) == -1) {
+                               cvs_printf("invalid date: %s", p);
+                               goto out;
+                       }
                }
 
                rev1 = rcs_translate_tag(jrev1, cf->file_rcs);
index 6740f66..e8f654f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ci.c,v 1.209 2010/07/28 09:07:11 ray Exp $    */
+/*     $OpenBSD: ci.c,v 1.210 2010/07/30 21:47:18 ray Exp $    */
 /*
  * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org>
  * All rights reserved.
@@ -136,7 +136,7 @@ checkin_main(int argc, char **argv)
                case 'd':
                        if (rcs_optarg == NULL)
                                pb.date = DATE_MTIME;
-                       else if ((pb.date = date_parse(rcs_optarg)) <= 0)
+                       else if ((pb.date = date_parse(rcs_optarg)) == -1)
                                errx(1, "invalid date");
                        break;
                case 'f':
@@ -994,7 +994,7 @@ checkin_parsekeyword(char *keystring, RCSNUM **rev, time_t *date,
                if (i < 5)
                        break;
                (void)xasprintf(&datestring, "%s %s", tokens[3], tokens[4]);
-               if ((*date = date_parse(datestring)) <= 0)
+               if ((*date = date_parse(datestring)) == -1)
                        errx(1, "could not parse date");
                xfree(datestring);
 
@@ -1021,7 +1021,7 @@ checkin_parsekeyword(char *keystring, RCSNUM **rev, time_t *date,
                if (i < 3)
                        break;
                (void)xasprintf(&datestring, "%s %s", tokens[1], tokens[2]);
-               if ((*date = date_parse(datestring)) <= 0)
+               if ((*date = date_parse(datestring)) == -1)
                        errx(1, "could not parse date");
                xfree(datestring);
                break;
index 90c9e14..a6860d0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: co.c,v 1.112 2010/07/28 09:07:11 ray Exp $    */
+/*     $OpenBSD: co.c,v 1.113 2010/07/30 21:47:18 ray Exp $    */
 /*
  * Copyright (c) 2005 Joris Vink <joris@openbsd.org>
  * All rights reserved.
@@ -261,8 +261,10 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
        RCSNUM *rev;
 
        rcsdate = givendate = -1;
-       if (date != NULL)
-               givendate = date_parse(date);
+       if (date != NULL && (givendate = date_parse(date)) == -1) {
+               warnx("invalid date: %s", date);
+               return -1;
+       }
 
        if (file->rf_ndelta == 0 && !(flags & QUIET))
                (void)fprintf(stderr,
@@ -303,7 +305,10 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
                TAILQ_FOREACH(rdp, &file->rf_delta, rd_list) {
                        if (date != NULL) {
                                fdate = asctime(&rdp->rd_date);
-                               rcsdate = date_parse(fdate);
+                               if ((rcsdate = date_parse(fdate)) == -1) {
+                                       warnx("invalid date: %s", fdate);
+                                       return -1;
+                               }
                                if (givendate <= rcsdate)
                                        continue;
                        }
index 43d4514..8f6ecf0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rlog.c,v 1.63 2010/07/23 21:46:05 ray Exp $   */
+/*     $OpenBSD: rlog.c,v 1.64 2010/07/30 21:47:18 ray Exp $   */
 /*
  * Copyright (c) 2005, 2009 Joris Vink <joris@openbsd.org>
  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -227,7 +227,8 @@ rlog_select_daterev(RCSFILE *rcsfile, char *date)
 
                if (last == NULL) {
                        flags |= RLOG_DATE_SINGLE;
-                       firstdate = date_parse(first);
+                       if ((firstdate = date_parse(first)) == -1)
+                               return -1;
                        delim = '\0';
                        last = "\0";
                } else {
@@ -237,22 +238,26 @@ rlog_select_daterev(RCSFILE *rcsfile, char *date)
 
                if (delim == '>' && *last == '\0') {
                        flags |= RLOG_DATE_EARLIER;
-                       firstdate = date_parse(first);
+                       if ((firstdate = date_parse(first)) == -1)
+                               return -1;
                }
 
                if (delim == '>' && *first == '\0' && *last != '\0') {
                        flags |= RLOG_DATE_LATER;
-                       firstdate = date_parse(last);
+                       if ((firstdate = date_parse(last)) == -1)
+                               return -1;
                }
 
                if (delim == '<' && *last == '\0') {
                        flags |= RLOG_DATE_LATER;
-                       firstdate = date_parse(first);
+                       if ((firstdate = date_parse(first)) == -1)
+                               return -1;
                }
 
                if (delim == '<' && *first == '\0' && *last != '\0') {
                        flags |= RLOG_DATE_EARLIER;
-                       firstdate = date_parse(last);
+                       if ((firstdate = date_parse(last)) == -1)
+                               return -1;
                }
 
                if (*first != '\0' && *last != '\0') {
@@ -265,6 +270,8 @@ rlog_select_daterev(RCSFILE *rcsfile, char *date)
                                firstdate = date_parse(last);
                                lastdate = date_parse(first);
                        }
+                       if (firstdate == -1 || lastdate == -1)
+                               return -1;
                }
 
                TAILQ_FOREACH(rdp, &(rcsfile->rf_delta), rd_list) {
@@ -343,9 +350,10 @@ rlog_file(const char *fname, RCSFILE *file)
 
        if (rflag == 1)
                nrev = rcs_rev_select(file, revisions);
-       else if (dflag == 1)
-               nrev = rlog_select_daterev(file, rlog_dates);
-       else
+       else if (dflag == 1) {
+               if ((nrev = rlog_select_daterev(file, rlog_dates)) == -1)
+                       errx(1, "invalid date: %s", rlog_dates);
+       } else
                nrev = file->rf_ndelta;
 
        if ((workfile = basename(fname)) == NULL)