Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
a8da1b33
Commit
a8da1b33
authored
Sep 30, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved date parsing in build/src/parse_date.c
parent
63c19b46
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
92 deletions
+95
-92
Makefile
build/Makefile
+3
-1
mongoose.c
build/src/mongoose.c
+0
-48
parse_date.c
build/src/parse_date.c
+49
-0
mongoose.c
mongoose.c
+43
-43
No files found.
build/Makefile
View file @
a8da1b33
...
@@ -24,7 +24,9 @@ EXE_SUFFIX =
...
@@ -24,7 +24,9 @@ EXE_SUFFIX =
CFLAGS
=
-std
=
c99
-O2
-W
-Wall
-pedantic
-pthread
-pipe
-I
..
$(CFLAGS_EXTRA)
CFLAGS
=
-std
=
c99
-O2
-W
-Wall
-pedantic
-pthread
-pipe
-I
..
$(CFLAGS_EXTRA)
VERSION
=
$(
shell
perl
-lne
\
VERSION
=
$(
shell
perl
-lne
\
'print $$1 if /define\s+MONGOOSE_VERSION\s+"(\S+
)
"/'
../mongoose.c
)
'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
TINY_SOURCES
=
../mongoose.c main.c
LUA_SOURCES
=
$(TINY_SOURCES)
sqlite3.c lsqlite3.c lua_5.2.1.c
LUA_SOURCES
=
$(TINY_SOURCES)
sqlite3.c lsqlite3.c lua_5.2.1.c
...
...
build/src/mongoose.c
View file @
a8da1b33
#include "internal.h"
#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
[]
=
{
static
const
char
*
config_options
[]
=
{
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_environment"
,
NULL
,
"cgi_environment"
,
NULL
,
...
@@ -1144,49 +1139,6 @@ static int get_request_len(const char *buf, int buf_len) {
...
@@ -1144,49 +1139,6 @@ static int get_request_len(const char *buf, int buf_len) {
return
0
;
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 '..',
// Protect against directory disclosure attack by removing '..',
// excessive '/' and '\' characters
// excessive '/' and '\' characters
static
void
remove_double_dots_and_double_slashes
(
char
*
s
)
{
static
void
remove_double_dots_and_double_slashes
(
char
*
s
)
{
...
...
build/src/parse_date.c
0 → 100644
View file @
a8da1b33
#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
;
}
mongoose.c
View file @
a8da1b33
...
@@ -708,6 +708,49 @@ static const char *month_names[] = {
...
@@ -708,6 +708,49 @@ static const char *month_names[] = {
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
"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
[]
=
{
static
const
char
*
config_options
[]
=
{
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_environment"
,
NULL
,
"cgi_environment"
,
NULL
,
...
@@ -1847,49 +1890,6 @@ static int get_request_len(const char *buf, int buf_len) {
...
@@ -1847,49 +1890,6 @@ static int get_request_len(const char *buf, int buf_len) {
return
0
;
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 '..',
// Protect against directory disclosure attack by removing '..',
// excessive '/' and '\' characters
// excessive '/' and '\' characters
static
void
remove_double_dots_and_double_slashes
(
char
*
s
)
{
static
void
remove_double_dots_and_double_slashes
(
char
*
s
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment