Skip to content

Commit 0b3fa70

Browse files
committed
Fix parsing problems in style file reader
Some variables were not initialized correctly when parsing a style file, which lead to some surprising behaviour with flags of one config line re-used by the next if the flags field of that line was empty. This could also have lead to buffer overflows in the first line being parsed. This commit also adds some more tests for the parsing code. See #1590
1 parent cff2a2d commit 0b3fa70

12 files changed

Lines changed: 269 additions & 5 deletions

src/taginfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ static unsigned get_tag_type(std::string const &tag)
8484

8585
bool read_style_file(std::string const &filename, export_list *exlist)
8686
{
87-
char osmtype[24];
88-
char tag[64];
89-
char datatype[24];
90-
char flags[128];
9187
bool enable_way_area = true;
9288

9389
FILE *const in = std::fopen(filename.c_str(), "rt");
@@ -110,6 +106,10 @@ bool read_style_file(std::string const &filename, export_list *exlist)
110106
}
111107

112108
//grab the expected fields for this row
109+
char osmtype[24] = {0};
110+
char tag[64] = {0};
111+
char datatype[24] = {0};
112+
char flags[128] = {0};
113113
int const fields = std::sscanf(buffer, "%23s %63s %23s %127s", osmtype,
114114
tag, datatype, flags);
115115
if (fields <= 0) { /* Blank line */
@@ -124,7 +124,7 @@ bool read_style_file(std::string const &filename, export_list *exlist)
124124
}
125125

126126
//place to keep info about this tag
127-
taginfo temp;
127+
taginfo temp{};
128128
temp.name = tag;
129129
temp.type = datatype;
130130
temp.flags = parse_tag_flags(flags, lineno);

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set_test(test-output-pgsql-area)
5656
set_test(test-output-pgsql-hstore-match-only)
5757
set_test(test-output-pgsql-int4)
5858
set_test(test-output-pgsql-schema)
59+
set_test(test-output-pgsql-style-file)
5960
set_test(test-output-pgsql-tablespace LABELS Tablespace)
6061
set_test(test-output-pgsql-validgeom)
6162
set_test(test-output-pgsql-z_order)

tests/style/comments.style

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is a comment
2+
3+
# Also comment

tests/style/data-types.style

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# OsmType Tag DataType Flags
2+
node,way name text linear
3+
way width real linear
4+
node,way population integer polygon

tests/style/empty.style

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# OsmType Tag DataType Flags
2+
way highway foo linear

tests/style/invalid-osm-type.style

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# OsmType Tag DataType Flags
2+
foo bar text linear

tests/style/missing.style

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OsmType Tag DataType Flags
2+
node node1 text linear
3+
node node2 text
4+
way way1 text polygon
5+
way way2 text

tests/style/node.style

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node access text linear

tests/style/valid.style

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OsmType Tag DataType Flags
2+
node node_text_linear text linear
3+
way way_text_linear text linear
4+
node,way both_text_linear text linear
5+
6+
node node_text_polygon text polygon
7+
way way_text_polygon text polygon
8+
node,way both_text_polygon text polygon
9+
10+
node,way both_nocolumn text nocolumn
11+
12+
node,way both_delete text delete

0 commit comments

Comments
 (0)