mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-19 11:09:42 +00:00
Moved date parsing in build/src/parse_date.c
This commit is contained in:
1 parent
63c19b4631
commit
a8da1b3334
4 files changed
+95
-92
No files matched your search
+3
-1
@@ -24,7 +24,9 @@ EXE_SUFFIX =
|
||||
CFLAGS = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe -I.. $(CFLAGS_EXTRA)
|
||||
VERSION = $(shell perl -lne \
|
||||
'print $$1 if /define\s+MONGOOSE_VERSION\s+"(\S+)"/' ../mongoose.c)
|
||||
SOURCES = src/internal.h src/string.c src/mongoose.c
|
||||
|
||||
# The order in which files are listed is important
|
||||
SOURCES = src/internal.h src/string.c src/parse_date.c src/mongoose.c
|
||||
|
||||
TINY_SOURCES = ../mongoose.c main.c
|
||||
LUA_SOURCES = $(TINY_SOURCES) sqlite3.c lsqlite3.c lua_5.2.1.c
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
#include "internal.h"
|
||||
|
||||
static const char *month_names[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
static const char *config_options[] = {
|
||||
"cgi_pattern", "**.cgi$|**.pl$|**.php$",
|
||||
"cgi_environment", NULL,
|
||||
@@ -1144,49 +1139,6 @@ static int get_request_len(const char *buf, int buf_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert month to the month number. Return -1 on error, or month number
|
||||
static int get_month_index(const char *s) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(month_names); i++)
|
||||
if (!strcmp(s, month_names[i]))
|
||||
return (int) i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int num_leap_years(int year) {
|
||||
return year / 4 - year / 100 + year / 400;
|
||||
}
|
||||
|
||||
// Parse UTC date-time string, and return the corresponding time_t value.
|
||||
static time_t parse_date_string(const char *datetime) {
|
||||
static const unsigned short days_before_month[] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
char month_str[32];
|
||||
int second, minute, hour, day, month, year, leap_days, days;
|
||||
time_t result = (time_t) 0;
|
||||
|
||||
if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d-%3s-%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6)) &&
|
||||
year > 1970 &&
|
||||
(month = get_month_index(month_str)) != -1) {
|
||||
leap_days = num_leap_years(year) - num_leap_years(1970);
|
||||
year -= 1970;
|
||||
days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
|
||||
result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Protect against directory disclosure attack by removing '..',
|
||||
// excessive '/' and '\' characters
|
||||
static void remove_double_dots_and_double_slashes(char *s) {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "internal.h"
|
||||
|
||||
static const char *month_names[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
// Convert month to the month number. Return -1 on error, or month number
|
||||
static int get_month_index(const char *s) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int) ARRAY_SIZE(month_names); i++)
|
||||
if (!strcmp(s, month_names[i]))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int num_leap_years(int year) {
|
||||
return year / 4 - year / 100 + year / 400;
|
||||
}
|
||||
|
||||
// Parse UTC date-time string, and return the corresponding time_t value.
|
||||
static time_t parse_date_string(const char *datetime) {
|
||||
static const unsigned short days_before_month[] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
char month_str[32];
|
||||
int second, minute, hour, day, month, year, leap_days, days;
|
||||
time_t result = (time_t) 0;
|
||||
|
||||
if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d-%3s-%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6)) &&
|
||||
year > 1970 &&
|
||||
(month = get_month_index(month_str)) != -1) {
|
||||
leap_days = num_leap_years(year) - num_leap_years(1970);
|
||||
year -= 1970;
|
||||
days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
|
||||
result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+43
-43
@@ -708,6 +708,49 @@ static const char *month_names[] = {
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
// Convert month to the month number. Return -1 on error, or month number
|
||||
static int get_month_index(const char *s) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int) ARRAY_SIZE(month_names); i++)
|
||||
if (!strcmp(s, month_names[i]))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int num_leap_years(int year) {
|
||||
return year / 4 - year / 100 + year / 400;
|
||||
}
|
||||
|
||||
// Parse UTC date-time string, and return the corresponding time_t value.
|
||||
static time_t parse_date_string(const char *datetime) {
|
||||
static const unsigned short days_before_month[] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
char month_str[32];
|
||||
int second, minute, hour, day, month, year, leap_days, days;
|
||||
time_t result = (time_t) 0;
|
||||
|
||||
if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d-%3s-%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6)) &&
|
||||
year > 1970 &&
|
||||
(month = get_month_index(month_str)) != -1) {
|
||||
leap_days = num_leap_years(year) - num_leap_years(1970);
|
||||
year -= 1970;
|
||||
days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
|
||||
result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char *config_options[] = {
|
||||
"cgi_pattern", "**.cgi$|**.pl$|**.php$",
|
||||
"cgi_environment", NULL,
|
||||
@@ -1847,49 +1890,6 @@ static int get_request_len(const char *buf, int buf_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert month to the month number. Return -1 on error, or month number
|
||||
static int get_month_index(const char *s) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(month_names); i++)
|
||||
if (!strcmp(s, month_names[i]))
|
||||
return (int) i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int num_leap_years(int year) {
|
||||
return year / 4 - year / 100 + year / 400;
|
||||
}
|
||||
|
||||
// Parse UTC date-time string, and return the corresponding time_t value.
|
||||
static time_t parse_date_string(const char *datetime) {
|
||||
static const unsigned short days_before_month[] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
char month_str[32];
|
||||
int second, minute, hour, day, month, year, leap_days, days;
|
||||
time_t result = (time_t) 0;
|
||||
|
||||
if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d-%3s-%d %d:%d:%d",
|
||||
&day, month_str, &year, &hour, &minute, &second) == 6)) &&
|
||||
year > 1970 &&
|
||||
(month = get_month_index(month_str)) != -1) {
|
||||
leap_days = num_leap_years(year) - num_leap_years(1970);
|
||||
year -= 1970;
|
||||
days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
|
||||
result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Protect against directory disclosure attack by removing '..',
|
||||
// excessive '/' and '\' characters
|
||||
static void remove_double_dots_and_double_slashes(char *s) {
|
||||
|
||||
Reference in new issue
Block a user