From: Michal Sekletar Date: Wed, 28 Aug 2024 14:01:26 +0000 (+0200) Subject: Reset string explicitely to prevent undefined behavior X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=HEAD;hp=a03412e91a80f762aff266a6c9e9a1f6f206942b;p=plocate Reset string explicitely to prevent undefined behavior --- diff --git a/NEWS b/NEWS index a7f0e25..fd58c53 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +plocate 1.1.22, January 12th, 2024 + + - Revert the updatedb change in 1.1.21 that did not open + pruned paths; it broke pruning of paths that were not at the root + (e.g. /foo/bar, as opposed to /foo). Reported by David Caldwell. + + plocate 1.1.21, January 6th, 2024 - Improve interactions between pruning and bind mount detection diff --git a/database-builder.cpp b/database-builder.cpp index f9dfb71..0655681 100644 --- a/database-builder.cpp +++ b/database-builder.cpp @@ -531,7 +531,15 @@ DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_siz hdr.max_version = 2; hdr.filename_index_offset_bytes = -1; hdr.zstd_dictionary_length_bytes = -1; + hdr.zstd_dictionary_offset_bytes = -1; // Dictionary offset is not known yet. hdr.check_visibility = check_visibility; + hdr.directory_data_length_bytes = 0; + hdr.directory_data_offset_bytes = 0; + hdr.next_zstd_dictionary_length_bytes = 0; + hdr.next_zstd_dictionary_offset_bytes = 0; + hdr.conf_block_length_bytes = 0; + hdr.conf_block_offset_bytes = 0; + fwrite(&hdr, sizeof(hdr), 1, outfp); if (dictionary.empty()) { @@ -543,13 +551,6 @@ DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_siz hdr.zstd_dictionary_length_bytes = dictionary.size(); cdict = ZSTD_createCDict(dictionary.data(), dictionary.size(), /*level=*/6); } - - hdr.directory_data_length_bytes = 0; - hdr.directory_data_offset_bytes = 0; - hdr.next_zstd_dictionary_length_bytes = 0; - hdr.next_zstd_dictionary_offset_bytes = 0; - hdr.conf_block_length_bytes = 0; - hdr.conf_block_offset_bytes = 0; } DatabaseReceiver *DatabaseBuilder::start_corpus(bool store_dir_times) diff --git a/meson.build b/meson.build index 04764b6..5e60e02 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('plocate', 'cpp', default_options: ['buildtype=debugoptimized','cpp_std=c++17'], version: '1.1.21-pre') +project('plocate', 'cpp', default_options: ['buildtype=debugoptimized','cpp_std=c++17'], version: '1.1.23-pre') add_project_arguments('-DGROUPNAME="' + get_option('locategroup') + '"', language: 'cpp') add_project_arguments('-DUPDATEDB_CONF="/etc/updatedb.conf"', language: 'cpp') diff --git a/plocate-updatedb.service.in b/plocate-updatedb.service.in index a075051..4d9c432 100644 --- a/plocate-updatedb.service.in +++ b/plocate-updatedb.service.in @@ -7,6 +7,7 @@ Type=oneshot ExecStart=@sbindir@/@updatedb_progname@ LimitNOFILE=131072 IOSchedulingClass=idle +Nice=19 PrivateTmp=true PrivateDevices=true diff --git a/plocate.cpp b/plocate.cpp index 519024e..36f087e 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -489,6 +489,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena start = steady_clock::now(); if (access("/", R_OK | X_OK)) { // We can't find anything, no need to bother... + close(fd); return 0; } @@ -534,6 +535,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena uint64_t matched = scan_all_docids(needles, fd, corpus); dprintf("Done in %.1f ms, found %" PRId64 " matches.\n", 1e3 * duration(steady_clock::now() - start).count(), matched); + close(fd); return matched; } @@ -592,6 +594,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena dprintf("Hashtable lookups done after %.1f ms.\n", 1e3 * duration(steady_clock::now() - start).count()); if (should_early_exit) { + close(fd); return 0; } @@ -677,6 +680,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena } engine.finish(); if (done) { + close(fd); return 0; } dprintf("Intersection done after %.1f ms. Doing final verification and printing:\n", @@ -685,6 +689,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena uint64_t matched = scan_docids(needles, cur_candidates, corpus, &engine); dprintf("Done in %.1f ms, found %" PRId64 " matches.\n", 1e3 * duration(steady_clock::now() - start).count(), matched); + close(fd); return matched; } @@ -794,6 +799,7 @@ void parse_dbpaths(const char *ptr, vector *output) if (*ptr == ':') { // Separator. output->push_back(move(str)); + str.clear(); ++ptr; continue; }