Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ CTAGS
tools/http_load/http_load
tools/jtest/jtest
tools/trafficserver.pc
tools/escape_mapper/escape_mapper

BUILDS
DEBUG
Expand Down
2 changes: 2 additions & 0 deletions proxy/logging/LogUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ escapify_url_common(Arena *arena, char *url, size_t len_in, int *len_out, char *
// historically this is what the traffic_server has done.
// Note that we leave codes beyond 127 unmodified.
//
// NOTE: any updates to this table should result in an update to:
// tools/escape_mapper/escape_mapper.cc.
static const unsigned char codes_to_escape[32] = {
0xFF, 0xFF, 0xFF,
0xFF, // control
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ else
noinst_PROGRAMS += escape_mapper/escape_mapper
endif

escape_mapper_escape_mapper_SOURCES = escape_mapper/escape_mapper.c
escape_mapper_escape_mapper_SOURCES = escape_mapper/escape_mapper.cc

all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(DATA)
@sed "s/ -fPIE//" tsxs > tsxs.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
limitations under the License.
*/

#include <stdio.h>
#include <string.h>
#include <iomanip>
#include <iostream>
#include <string_view>

void
add_mapping(unsigned char *table, char c)
Expand All @@ -39,7 +40,7 @@ main(int argc, char *argv[])
{
// only support a single arg that contains all the chars we wish to escapify
if (argc > 1 && argc != 2) {
printf("Provide a single argument with a list of characters to add to the default encoding table\n");
std::cerr << "Provide a single argument with a list of characters to add to the default encoding table." << std::endl;
return (1);
}

Expand All @@ -48,33 +49,37 @@ main(int argc, char *argv[])
' ', '"', '#', '%', '<', '>', '[', ']', '\\', '^', '`', '{', '|', '}', '~', 0x7F,
};

unsigned char escape_codes[32];
memset(&escape_codes[0], 0, sizeof(escape_codes));
unsigned char escape_codes[32] = {0};

// indexes 0-3 are marked as "control"
for (int i = 0; i < 4; i++) {
escape_codes[i] = 0xFF;
}

for (unsigned long i = 0; i < sizeof(to_escape) / sizeof(to_escape[0]); i++) {
add_mapping(&escape_codes[0], to_escape[i]);
// add_mapping performs a logical or on the entries, so the above 0xFF values
// will persist.
for (auto char_to_escape : to_escape) {
add_mapping(&escape_codes[0], char_to_escape);
Comment on lines +59 to +62
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched the file to C++ to make some of these loops a bit easier to process.

}

// add the chars specified in argv
if (argc > 1) {
for (unsigned long i = 0; i < strlen(argv[1]); i++) {
printf("Adding %c to escape mapping table\n", argv[1][i]);
add_mapping(&escape_codes[0], argv[1][i]);
std::string_view escape_characters{argv[1]};
for (auto const char_to_escape : escape_characters) {
std::cout << "Adding '" << char_to_escape << "' to escape mapping table." << std::endl;
add_mapping(&escape_codes[0], char_to_escape);
}

printf("\n");
std::cout << std::endl;
}

printf("%s Escape Mapping Table:\n", (argc > 1) ? "New" : "Default");
std::string_view qualification{((argc > 1) ? "New" : "Default")};
std::cout << qualification << " Escape Mapping Table:" << std::endl;

for (unsigned long i = 0; i < sizeof(escape_codes) / sizeof(escape_codes[0]); i++) {
printf(" %2lu: %#04x\n", i, escape_codes[i]);
std::cout << std::dec << std::setfill(' ') << std::setw(4) << i << ": 0x";
auto const escape_code = static_cast<int>(escape_codes[i]);
std::cout << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << escape_code << std::endl;
}

return (0);
return 0;
}