Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-dispatch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
uplex-varnish
libvmod-dispatch
Commits
5e872182
Commit
5e872182
authored
Jan 29, 2018
by
Geoff Simmons
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate code for range checking.
parent
9524c583
Pipeline
#417
skipped
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
52 deletions
+31
-52
vmod_dispatch.c
src/vmod_dispatch.c
+31
-52
No files found.
src/vmod_dispatch.c
View file @
5e872182
...
...
@@ -83,6 +83,29 @@ struct vmod_dispatch_vcl {
static
struct
vrt_ctx
dummy_ctx
=
{
.
magic
=
VRT_CTX_MAGIC
};
static
int
check_range
(
VRT_CTX
,
VCL_INT
n
,
unsigned
max
,
struct
vbitmap
*
const
restrict
bitmap
,
const
char
*
restrict
const
type
,
const
char
*
restrict
const
name
,
const
char
*
restrict
const
method
)
{
if
(
n
<
0
)
{
VERR
(
ctx
,
"%s.%s(%ld): n must be >= 0"
,
name
,
method
,
n
);
return
0
;
}
if
(
n
>=
max
)
{
VERR
(
ctx
,
"%s.%s(%ld): highest %s number is %d"
,
name
,
method
,
n
,
type
,
max
-
1
);
return
0
;
}
if
(
!
vbit_test
(
bitmap
,
n
))
{
VERR
(
ctx
,
"%s.%s(%ld): %s %ld was not added"
,
name
,
method
,
n
,
type
,
n
);
return
0
;
}
return
1
;
}
VCL_VOID
vmod_label__init
(
VRT_CTX
,
struct
vmod_dispatch_label
**
labelp
,
const
char
*
vcl_name
)
...
...
@@ -193,20 +216,9 @@ vmod_label_go(VRT_CTX, struct vmod_dispatch_label *label, VCL_INT n)
n
);
return
;
}
if
(
n
<
0
)
{
VERR
(
ctx
,
"%s.go(%ld): n must be >= 0"
,
label
->
vcl_name
,
n
);
return
;
}
if
(
n
>=
label
->
nvcls
)
{
VERR
(
ctx
,
"%s.go(%ld): highest label number is %d"
,
label
->
vcl_name
,
n
,
label
->
nvcls
-
1
);
return
;
}
if
(
!
vbit_test
(
label
->
bitmap
,
n
))
{
VERR
(
ctx
,
"%s.go(%ld): label %ld was not added"
,
label
->
vcl_name
,
n
,
n
);
if
(
!
check_range
(
ctx
,
n
,
label
->
nvcls
,
label
->
bitmap
,
"label"
,
label
->
vcl_name
,
"go"
))
return
;
}
VRT_vcl_select
(
ctx
,
label
->
vcl
[
n
]);
VRT_handling
(
ctx
,
VCL_RET_VCL
);
}
...
...
@@ -217,20 +229,9 @@ vmod_label_string(VRT_CTX, struct vmod_dispatch_label *label, VCL_INT n)
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
label
,
VMOD_DISPATCH_LABEL_MAGIC
);
if
(
n
<
0
)
{
VERR
(
ctx
,
"%s.string(%ld): n must be >= 0"
,
label
->
vcl_name
,
n
);
return
NULL
;
}
if
(
n
>=
label
->
nvcls
)
{
VERR
(
ctx
,
"%s.string(%ld): highest label number is %d"
,
label
->
vcl_name
,
n
,
label
->
nvcls
-
1
);
if
(
!
check_range
(
ctx
,
n
,
label
->
nvcls
,
label
->
bitmap
,
"label"
,
label
->
vcl_name
,
"string"
))
return
NULL
;
}
if
(
!
vbit_test
(
label
->
bitmap
,
n
))
{
VERR
(
ctx
,
"%s.string(%ld): label %ld was not added"
,
label
->
vcl_name
,
n
,
n
);
return
NULL
;
}
AN
(
label
->
string
[
n
]);
return
label
->
string
[
n
];
}
...
...
@@ -379,20 +380,9 @@ vmod_sub_call(VRT_CTX, struct vmod_dispatch_sub *sub, VCL_INT n)
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
sub
,
VMOD_DISPATCH_SUB_MAGIC
);
if
(
n
<
0
)
{
VERR
(
ctx
,
"%s.call(%ld): n must be >= 0"
,
sub
->
vcl_name
,
n
);
return
;
}
if
(
n
>=
sub
->
nsubs
)
{
VERR
(
ctx
,
"%s.call(%ld): highest sub number is %d"
,
sub
->
vcl_name
,
n
,
sub
->
nsubs
-
1
);
return
;
}
if
(
!
vbit_test
(
sub
->
bitmap
,
n
))
{
VERR
(
ctx
,
"%s.call(%ld): sub %ld was not added"
,
sub
->
vcl_name
,
n
,
n
);
if
(
!
check_range
(
ctx
,
n
,
sub
->
nsubs
,
sub
->
bitmap
,
"sub"
,
sub
->
vcl_name
,
"call"
))
return
;
}
AN
(
sub
->
func
[
n
]);
sub
->
func
[
n
](
ctx
);
}
...
...
@@ -403,20 +393,9 @@ vmod_sub_string(VRT_CTX, struct vmod_dispatch_sub *sub, VCL_INT n)
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
sub
,
VMOD_DISPATCH_SUB_MAGIC
);
if
(
n
<
0
)
{
VERR
(
ctx
,
"%s.string(%ld): n must be >= 0"
,
sub
->
vcl_name
,
n
);
return
NULL
;
}
if
(
n
>=
sub
->
nsubs
)
{
VERR
(
ctx
,
"%s.string(%ld): highest sub number is %d"
,
sub
->
vcl_name
,
n
,
sub
->
nsubs
-
1
);
if
(
!
check_range
(
ctx
,
n
,
sub
->
nsubs
,
sub
->
bitmap
,
"sub"
,
sub
->
vcl_name
,
"string"
))
return
NULL
;
}
if
(
!
vbit_test
(
sub
->
bitmap
,
n
))
{
VERR
(
ctx
,
"%s.string(%ld): sub %ld was not added"
,
sub
->
vcl_name
,
n
,
n
);
return
NULL
;
}
AN
(
sub
->
string
[
n
]);
return
sub
->
string
[
n
];
}
...
...
Geoff Simmons
@geoff
mentioned in issue
#1
·
Jan 29, 2018
mentioned in issue
#1
mentioned in issue #1
Toggle commit list
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