return result == 0;
}
+int
+match_no_newline(
+ const char * regex,
+ const char * str)
+{
+ regex_t regc;
+ int result;
+ char errmsg[STR_SIZE];
+
+ if((result = regcomp(®c, regex,
+ REG_EXTENDED|REG_NOSUB)) != 0) {
+ regerror(result, ®c, errmsg, SIZEOF(errmsg));
+ error(_("regex \"%s\": %s"), regex, errmsg);
+ /*NOTREACHED*/
+ }
+
+ if((result = regexec(®c, str, 0, 0, 0)) != 0
+ && result != REG_NOMATCH) {
+ regerror(result, ®c, errmsg, SIZEOF(errmsg));
+ error(_("regex \"%s\": %s"), regex, errmsg);
+ /*NOTREACHED*/
+ }
+
+ regfree(®c);
+
+ return result == 0;
+}
+
char *
validate_glob(
const char * glob)
return match_word(glob, disk, '/');
}
+static int
+alldigits(
+ const char *str)
+{
+ while (*str) {
+ if (!isdigit((int)*(str++)))
+ return 0;
+ }
+ return 1;
+}
+
int
match_datestamp(
const char * dateexp,
int match_exact;
if(strlen(dateexp) >= 100 || strlen(dateexp) < 1) {
- error(_("Illegal datestamp expression %s"),dateexp);
- /*NOTREACHED*/
+ goto illegal;
}
+ /* strip and ignore an initial "^" */
if(dateexp[0] == '^') {
- strncpy(mydateexp, dateexp+1, strlen(dateexp)-1);
- mydateexp[strlen(dateexp)-1] = '\0';
+ strncpy(mydateexp, dateexp+1, sizeof(mydateexp)-1);
+ mydateexp[sizeof(mydateexp)-1] = '\0';
}
else {
- strncpy(mydateexp, dateexp, strlen(dateexp));
- mydateexp[strlen(dateexp)] = '\0';
+ strncpy(mydateexp, dateexp, sizeof(mydateexp)-1);
+ mydateexp[sizeof(mydateexp)-1] = '\0';
}
- if(mydateexp[strlen(mydateexp)] == '$') {
+ if(mydateexp[strlen(mydateexp)-1] == '$') {
match_exact = 1;
- mydateexp[strlen(mydateexp)] = '\0';
+ mydateexp[strlen(mydateexp)-1] = '\0'; /* strip the trailing $ */
}
else
match_exact = 0;
+ /* a single dash represents a date range */
if((dash = strchr(mydateexp,'-'))) {
- if(match_exact == 1) {
- error(_("Illegal datestamp expression %s"),dateexp);
- /*NOTREACHED*/
+ if(match_exact == 1 || strchr(dash+1, '-')) {
+ goto illegal;
}
- len = (size_t)(dash - mydateexp);
- len_suffix = strlen(dash) - 1;
- len_prefix = len - len_suffix;
+
+ /* format: XXXYYYY-ZZZZ, indicating dates XXXYYYY to XXXZZZZ */
+
+ len = (size_t)(dash - mydateexp); /* length of XXXYYYY */
+ len_suffix = strlen(dash) - 1; /* length of ZZZZ */
+ if (len_suffix > len) goto illegal;
+ len_prefix = len - len_suffix; /* length of XXX */
dash++;
+
strncpy(firstdate, mydateexp, len);
firstdate[len] = '\0';
strncpy(lastdate, mydateexp, len_prefix);
strncpy(&(lastdate[len_prefix]), dash, len_suffix);
lastdate[len] = '\0';
+ if (!alldigits(firstdate) || !alldigits(lastdate))
+ goto illegal;
+ if (strncmp(firstdate, lastdate, strlen(firstdate)) > 0)
+ goto illegal;
return ((strncmp(datestamp, firstdate, strlen(firstdate)) >= 0) &&
(strncmp(datestamp, lastdate , strlen(lastdate)) <= 0));
}
else {
+ if (!alldigits(mydateexp))
+ goto illegal;
if(match_exact == 1) {
return (strcmp(datestamp, mydateexp) == 0);
}
return (strncmp(datestamp, mydateexp, strlen(mydateexp)) == 0);
}
}
+illegal:
+ error(_("Illegal datestamp expression %s"),dateexp);
+ /*NOTREACHED*/
}