From 5b4d91d76eac44b5b37b3d8088fda8b7f6204f15 Mon Sep 17 00:00:00 2001 From: Pete Warden Date: Tue, 4 Feb 2014 17:20:57 -0800 Subject: [PATCH] Fix for buffer overflow problem with long filenames when setting up the LevelDB --- examples/convert_imageset.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/convert_imageset.cpp b/examples/convert_imageset.cpp index 01c5f1ad..ee0e3adf 100644 --- a/examples/convert_imageset.cpp +++ b/examples/convert_imageset.cpp @@ -66,7 +66,8 @@ int main(int argc, char** argv) { string root_folder(argv[1]); Datum datum; int count = 0; - char key_cstr[100]; + const int maxKeyLength = 256; + char key_cstr[maxKeyLength]; leveldb::WriteBatch* batch = new leveldb::WriteBatch(); for (int line_id = 0; line_id < lines.size(); ++line_id) { if (!ReadImageToDatum(root_folder + lines[line_id].first, lines[line_id].second, @@ -74,7 +75,7 @@ int main(int argc, char** argv) { continue; }; // sequential - sprintf(key_cstr, "%08d_%s", line_id, lines[line_id].first.c_str()); + snprintf(key_cstr, maxKeyLength, "%08d_%s", line_id, lines[line_id].first.c_str()); string value; // get the value datum.SerializeToString(&value);