Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Knot DNS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Knot projects
Knot DNS
Commits
a3d1fb1c
Commit
a3d1fb1c
authored
Oct 25, 2017
by
Daniel Salzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zscanner: fix segfault during final block deinitialization
parent
521a519d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
51 deletions
+48
-51
src/zscanner/scanner.c.g2
src/zscanner/scanner.c.g2
+16
-17
src/zscanner/scanner.c.t0
src/zscanner/scanner.c.t0
+16
-17
src/zscanner/scanner.rl
src/zscanner/scanner.rl
+16
-17
No files found.
src/zscanner/scanner.c.g2
View file @
a3d1fb1c
...
@@ -146,7 +146,8 @@ int zs_init(
...
@@ -146,7 +146,8 @@ int zs_init(
}
}
static void input_deinit(
static void input_deinit(
zs_scanner_t *s)
zs_scanner_t *s,
bool keep_filename)
{
{
// Deinit the file input.
// Deinit the file input.
if (s->file.descriptor != -1) {
if (s->file.descriptor != -1) {
...
@@ -159,6 +160,10 @@ static void input_deinit(
...
@@ -159,6 +160,10 @@ static void input_deinit(
// Close the opened file.
// Close the opened file.
close(s->file.descriptor);
close(s->file.descriptor);
s->file.descriptor = -1;
s->file.descriptor = -1;
}
// Keep file name for possible trailing error report.
if (!keep_filename) {
free(s->file.name);
free(s->file.name);
s->file.name = NULL;
s->file.name = NULL;
}
}
...
@@ -178,7 +183,7 @@ void zs_deinit(
...
@@ -178,7 +183,7 @@ void zs_deinit(
return;
return;
}
}
input_deinit(s);
input_deinit(s
, false
);
free(s->path);
free(s->path);
}
}
...
@@ -197,20 +202,14 @@ static int set_input_string(
...
@@ -197,20 +202,14 @@ static int set_input_string(
return -1;
return -1;
}
}
// Keep previous input file context if final block parsing.
if (!final_block) {
// Deinit possibly opened file.
// Deinit possibly opened file.
input_deinit(s);
input_deinit(s, final_block);
}
// Set the scanner input limits.
// Set the scanner input limits.
s->input.start = input;
s->input.start = input;
s->input.current = input;
s->input.current = input;
s->input.end = input + size;
s->input.end = input + size;
s->input.eof = final_block;
if (final_block) {
s->input.eof = true;
}
return 0;
return 0;
}
}
...
@@ -239,7 +238,7 @@ int zs_set_input_file(
...
@@ -239,7 +238,7 @@ int zs_set_input_file(
}
}
// Deinit possibly opened file.
// Deinit possibly opened file.
input_deinit(s);
input_deinit(s
, false
);
// Try to open the file.
// Try to open the file.
s->file.descriptor = open(file_name, O_RDONLY);
s->file.descriptor = open(file_name, O_RDONLY);
...
@@ -253,7 +252,7 @@ int zs_set_input_file(
...
@@ -253,7 +252,7 @@ int zs_set_input_file(
if (fstat(s->file.descriptor, &file_stat) == -1 ||
if (fstat(s->file.descriptor, &file_stat) == -1 ||
!S_ISREG(file_stat.st_mode)) {
!S_ISREG(file_stat.st_mode)) {
ERR(ZS_FILE_INVALID);
ERR(ZS_FILE_INVALID);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
@@ -264,7 +263,7 @@ int zs_set_input_file(
...
@@ -264,7 +263,7 @@ int zs_set_input_file(
s->file.descriptor, 0);
s->file.descriptor, 0);
if (start == MAP_FAILED) {
if (start == MAP_FAILED) {
ERR(ZS_FILE_MMAP);
ERR(ZS_FILE_MMAP);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
@@ -285,19 +284,19 @@ int zs_set_input_file(
...
@@ -285,19 +284,19 @@ int zs_set_input_file(
free(full_name);
free(full_name);
if (s->path == NULL) {
if (s->path == NULL) {
ERR(ZS_ENOMEM);
ERR(ZS_ENOMEM);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
} else {
} else {
ERR(ZS_FILE_PATH);
ERR(ZS_FILE_PATH);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
s->file.name = strdup(file_name);
s->file.name = strdup(file_name);
if (s->file.name == NULL) {
if (s->file.name == NULL) {
ERR(ZS_ENOMEM);
ERR(ZS_ENOMEM);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
src/zscanner/scanner.c.t0
View file @
a3d1fb1c
...
@@ -5354,7 +5354,8 @@ int zs_init(
...
@@ -5354,7 +5354,8 @@ int zs_init(
}
}
static void input_deinit(
static void input_deinit(
zs_scanner_t *s)
zs_scanner_t *s,
bool keep_filename)
{
{
// Deinit the file input.
// Deinit the file input.
if (s->file.descriptor != -1) {
if (s->file.descriptor != -1) {
...
@@ -5367,6 +5368,10 @@ static void input_deinit(
...
@@ -5367,6 +5368,10 @@ static void input_deinit(
// Close the opened file.
// Close the opened file.
close(s->file.descriptor);
close(s->file.descriptor);
s->file.descriptor = -1;
s->file.descriptor = -1;
}
// Keep file name for possible trailing error report.
if (!keep_filename) {
free(s->file.name);
free(s->file.name);
s->file.name = NULL;
s->file.name = NULL;
}
}
...
@@ -5386,7 +5391,7 @@ void zs_deinit(
...
@@ -5386,7 +5391,7 @@ void zs_deinit(
return;
return;
}
}
input_deinit(s);
input_deinit(s
, false
);
free(s->path);
free(s->path);
}
}
...
@@ -5405,20 +5410,14 @@ static int set_input_string(
...
@@ -5405,20 +5410,14 @@ static int set_input_string(
return -1;
return -1;
}
}
// Keep previous input file context if final block parsing.
if (!final_block) {
// Deinit possibly opened file.
// Deinit possibly opened file.
input_deinit(s);
input_deinit(s, final_block);
}
// Set the scanner input limits.
// Set the scanner input limits.
s->input.start = input;
s->input.start = input;
s->input.current = input;
s->input.current = input;
s->input.end = input + size;
s->input.end = input + size;
s->input.eof = final_block;
if (final_block) {
s->input.eof = true;
}
return 0;
return 0;
}
}
...
@@ -5447,7 +5446,7 @@ int zs_set_input_file(
...
@@ -5447,7 +5446,7 @@ int zs_set_input_file(
}
}
// Deinit possibly opened file.
// Deinit possibly opened file.
input_deinit(s);
input_deinit(s
, false
);
// Try to open the file.
// Try to open the file.
s->file.descriptor = open(file_name, O_RDONLY);
s->file.descriptor = open(file_name, O_RDONLY);
...
@@ -5461,7 +5460,7 @@ int zs_set_input_file(
...
@@ -5461,7 +5460,7 @@ int zs_set_input_file(
if (fstat(s->file.descriptor, &file_stat) == -1 ||
if (fstat(s->file.descriptor, &file_stat) == -1 ||
!S_ISREG(file_stat.st_mode)) {
!S_ISREG(file_stat.st_mode)) {
ERR(ZS_FILE_INVALID);
ERR(ZS_FILE_INVALID);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
@@ -5472,7 +5471,7 @@ int zs_set_input_file(
...
@@ -5472,7 +5471,7 @@ int zs_set_input_file(
s->file.descriptor, 0);
s->file.descriptor, 0);
if (start == MAP_FAILED) {
if (start == MAP_FAILED) {
ERR(ZS_FILE_MMAP);
ERR(ZS_FILE_MMAP);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
@@ -5493,19 +5492,19 @@ int zs_set_input_file(
...
@@ -5493,19 +5492,19 @@ int zs_set_input_file(
free(full_name);
free(full_name);
if (s->path == NULL) {
if (s->path == NULL) {
ERR(ZS_ENOMEM);
ERR(ZS_ENOMEM);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
} else {
} else {
ERR(ZS_FILE_PATH);
ERR(ZS_FILE_PATH);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
s->file.name = strdup(file_name);
s->file.name = strdup(file_name);
if (s->file.name == NULL) {
if (s->file.name == NULL) {
ERR(ZS_ENOMEM);
ERR(ZS_ENOMEM);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
...
src/zscanner/scanner.rl
View file @
a3d1fb1c
...
@@ -147,7 +147,8 @@ int zs_init(
...
@@ -147,7 +147,8 @@ int zs_init(
}
}
static void input_deinit(
static void input_deinit(
zs_scanner_t *s)
zs_scanner_t *s,
bool keep_filename)
{
{
// Deinit the file input.
// Deinit the file input.
if (s->file.descriptor != -1) {
if (s->file.descriptor != -1) {
...
@@ -160,6 +161,10 @@ static void input_deinit(
...
@@ -160,6 +161,10 @@ static void input_deinit(
// Close the opened file.
// Close the opened file.
close(s->file.descriptor);
close(s->file.descriptor);
s->file.descriptor = -1;
s->file.descriptor = -1;
}
// Keep file name for possible trailing error report.
if (!keep_filename) {
free(s->file.name);
free(s->file.name);
s->file.name = NULL;
s->file.name = NULL;
}
}
...
@@ -179,7 +184,7 @@ void zs_deinit(
...
@@ -179,7 +184,7 @@ void zs_deinit(
return;
return;
}
}
input_deinit(s);
input_deinit(s
, false
);
free(s->path);
free(s->path);
}
}
...
@@ -198,20 +203,14 @@ static int set_input_string(
...
@@ -198,20 +203,14 @@ static int set_input_string(
return -1;
return -1;
}
}
// Keep previous input file context if final block parsing.
if (!final_block) {
// Deinit possibly opened file.
// Deinit possibly opened file.
input_deinit(s);
input_deinit(s, final_block);
}
// Set the scanner input limits.
// Set the scanner input limits.
s->input.start = input;
s->input.start = input;
s->input.current = input;
s->input.current = input;
s->input.end = input + size;
s->input.end = input + size;
s->input.eof = final_block;
if (final_block) {
s->input.eof = true;
}
return 0;
return 0;
}
}
...
@@ -240,7 +239,7 @@ int zs_set_input_file(
...
@@ -240,7 +239,7 @@ int zs_set_input_file(
}
}
// Deinit possibly opened file.
// Deinit possibly opened file.
input_deinit(s);
input_deinit(s
, false
);
// Try to open the file.
// Try to open the file.
s->file.descriptor = open(file_name, O_RDONLY);
s->file.descriptor = open(file_name, O_RDONLY);
...
@@ -254,7 +253,7 @@ int zs_set_input_file(
...
@@ -254,7 +253,7 @@ int zs_set_input_file(
if (fstat(s->file.descriptor, &file_stat) == -1 ||
if (fstat(s->file.descriptor, &file_stat) == -1 ||
!S_ISREG(file_stat.st_mode)) {
!S_ISREG(file_stat.st_mode)) {
ERR(ZS_FILE_INVALID);
ERR(ZS_FILE_INVALID);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
@@ -265,7 +264,7 @@ int zs_set_input_file(
...
@@ -265,7 +264,7 @@ int zs_set_input_file(
s->file.descriptor, 0);
s->file.descriptor, 0);
if (start == MAP_FAILED) {
if (start == MAP_FAILED) {
ERR(ZS_FILE_MMAP);
ERR(ZS_FILE_MMAP);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
@@ -286,19 +285,19 @@ int zs_set_input_file(
...
@@ -286,19 +285,19 @@ int zs_set_input_file(
free(full_name);
free(full_name);
if (s->path == NULL) {
if (s->path == NULL) {
ERR(ZS_ENOMEM);
ERR(ZS_ENOMEM);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
} else {
} else {
ERR(ZS_FILE_PATH);
ERR(ZS_FILE_PATH);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
s->file.name = strdup(file_name);
s->file.name = strdup(file_name);
if (s->file.name == NULL) {
if (s->file.name == NULL) {
ERR(ZS_ENOMEM);
ERR(ZS_ENOMEM);
input_deinit(s);
input_deinit(s
, false
);
return -1;
return -1;
}
}
...
...
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