View | Details | Raw Unified | Return to bug 15284
Collapse All | Expand All

(-)amanda/trunk/common-src/match.c (-14 / +39 lines)
Lines 530-535 Link Here
530
    return match_word(glob, disk, '/');
530
    return match_word(glob, disk, '/');
531
}
531
}
532
532
533
static int
534
alldigits(
535
    const char *str)
536
{
537
    while (*str) {
538
	if (!isdigit((int)*(str++)))
539
	    return 0;
540
    }
541
    return 1;
542
}
543
533
int
544
int
534
match_datestamp(
545
match_datestamp(
535
    const char *	dateexp,
546
    const char *	dateexp,
Lines 543-587 Link Here
543
    int match_exact;
554
    int match_exact;
544
555
545
    if(strlen(dateexp) >= 100 || strlen(dateexp) < 1) {
556
    if(strlen(dateexp) >= 100 || strlen(dateexp) < 1) {
546
	error(_("Illegal datestamp expression %s"),dateexp);
557
	goto illegal;
547
	/*NOTREACHED*/
548
    }
558
    }
549
   
559
   
560
    /* strip and ignore an initial "^" */
550
    if(dateexp[0] == '^') {
561
    if(dateexp[0] == '^') {
551
	strncpy(mydateexp, dateexp+1, strlen(dateexp)-1); 
562
	strncpy(mydateexp, dateexp+1, sizeof(mydateexp)-1);
552
	mydateexp[strlen(dateexp)-1] = '\0';
563
	mydateexp[sizeof(mydateexp)-1] = '\0';
553
    }
564
    }
554
    else {
565
    else {
555
	strncpy(mydateexp, dateexp, strlen(dateexp));
566
	strncpy(mydateexp, dateexp, sizeof(mydateexp)-1);
556
	mydateexp[strlen(dateexp)] = '\0';
567
	mydateexp[sizeof(mydateexp)] = '\0';
557
    }
568
    }
558
569
559
    if(mydateexp[strlen(mydateexp)] == '$') {
570
    if(mydateexp[strlen(mydateexp)-1] == '$') {
560
	match_exact = 1;
571
	match_exact = 1;
561
	mydateexp[strlen(mydateexp)] = '\0';
572
	mydateexp[strlen(mydateexp)-1] = '\0';	/* strip the trailing $ */
562
    }
573
    }
563
    else
574
    else
564
	match_exact = 0;
575
	match_exact = 0;
565
576
577
    /* a single dash represents a date range */
566
    if((dash = strchr(mydateexp,'-'))) {
578
    if((dash = strchr(mydateexp,'-'))) {
567
	if(match_exact == 1) {
579
	if(match_exact == 1 || strchr(dash+1, '-')) {
568
	    error(_("Illegal datestamp expression %s"),dateexp);
580
	    goto illegal;
569
	    /*NOTREACHED*/
570
	}
581
	}
571
	len = (size_t)(dash - mydateexp);
582
572
	len_suffix = strlen(dash) - 1;
583
	/* format: XXXYYYY-ZZZZ, indicating dates XXXYYYY to XXXZZZZ */
573
	len_prefix = len - len_suffix;
584
585
	len = (size_t)(dash - mydateexp);   /* length of XXXYYYY */
586
	len_suffix = strlen(dash) - 1;	/* length of ZZZZ */
587
	if (len_suffix > len) goto illegal;
588
	len_prefix = len - len_suffix; /* length of XXX */
574
589
575
	dash++;
590
	dash++;
591
576
	strncpy(firstdate, mydateexp, len);
592
	strncpy(firstdate, mydateexp, len);
577
	firstdate[len] = '\0';
593
	firstdate[len] = '\0';
578
	strncpy(lastdate, mydateexp, len_prefix);
594
	strncpy(lastdate, mydateexp, len_prefix);
579
	strncpy(&(lastdate[len_prefix]), dash, len_suffix);
595
	strncpy(&(lastdate[len_prefix]), dash, len_suffix);
580
	lastdate[len] = '\0';
596
	lastdate[len] = '\0';
597
	if (!alldigits(firstdate) || !alldigits(lastdate))
598
	    goto illegal;
599
	if (strncmp(firstdate, lastdate, strlen(firstdate)) > 0)
600
	    goto illegal;
581
	return ((strncmp(datestamp, firstdate, strlen(firstdate)) >= 0) &&
601
	return ((strncmp(datestamp, firstdate, strlen(firstdate)) >= 0) &&
582
		(strncmp(datestamp, lastdate , strlen(lastdate))  <= 0));
602
		(strncmp(datestamp, lastdate , strlen(lastdate))  <= 0));
583
    }
603
    }
584
    else {
604
    else {
605
	if (!alldigits(mydateexp))
606
	    goto illegal;
585
	if(match_exact == 1) {
607
	if(match_exact == 1) {
586
	    return (strcmp(datestamp, mydateexp) == 0);
608
	    return (strcmp(datestamp, mydateexp) == 0);
587
	}
609
	}
Lines 589-594 Link Here
589
	    return (strncmp(datestamp, mydateexp, strlen(mydateexp)) == 0);
611
	    return (strncmp(datestamp, mydateexp, strlen(mydateexp)) == 0);
590
	}
612
	}
591
    }
613
    }
614
illegal:
615
	error(_("Illegal datestamp expression %s"),dateexp);
616
	/*NOTREACHED*/
592
}
617
}
593
618
594
619

Return to bug 15284