]> git.sesse.net Git - plocate/commitdiff
Reset string explicitely to prevent undefined behavior master
authorMichal Sekletar <msekleta@redhat.com>
Wed, 28 Aug 2024 14:01:26 +0000 (16:01 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Wed, 28 Aug 2024 16:24:49 +0000 (18:24 +0200)
NEWS
database-builder.cpp
meson.build
plocate-updatedb.service.in
plocate.cpp

diff --git a/NEWS b/NEWS
index a7f0e25f9abc21d0f99b6973f1b50f747c6f9e60..fd58c5369b8a03dd09fd80d7ea6bf7c9848450d3 100644 (file)
--- 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
index f9dfb715391b3be7c4c521710d48f86b3b10795b..0655681ffe2a1ca3e61384ca0484257c6e253e31 100644 (file)
@@ -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)
index 04764b62d8fec846a253b1df6089d44d004d2781..5e60e02b414d37b2172662f159caf72f95ab1d1d 100644 (file)
@@ -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')
index a07505126153524fc664972a3c4f56ec6c254331..4d9c432a239884355e2e46b853213a5ba87cfac9 100644 (file)
@@ -7,6 +7,7 @@ Type=oneshot
 ExecStart=@sbindir@/@updatedb_progname@
 LimitNOFILE=131072
 IOSchedulingClass=idle
+Nice=19
 
 PrivateTmp=true
 PrivateDevices=true
index 519024e07c5b31d04f96db1cc085e8313bb4c39b..36f087e348df241398dbfec4a317e198d1e19184 100644 (file)
@@ -489,6 +489,7 @@ uint64_t do_search_file(const vector<Needle> &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<Needle> &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<float>(steady_clock::now() - start).count(), matched);
+               close(fd);
                return matched;
        }
 
@@ -592,6 +594,7 @@ uint64_t do_search_file(const vector<Needle> &needles, const std::string &filena
        dprintf("Hashtable lookups done after %.1f ms.\n", 1e3 * duration<float>(steady_clock::now() - start).count());
 
        if (should_early_exit) {
+               close(fd);
                return 0;
        }
 
@@ -677,6 +680,7 @@ uint64_t do_search_file(const vector<Needle> &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<Needle> &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<float>(steady_clock::now() - start).count(), matched);
+       close(fd);
        return matched;
 }
 
@@ -794,6 +799,7 @@ void parse_dbpaths(const char *ptr, vector<string> *output)
                if (*ptr == ':') {
                        // Separator.
                        output->push_back(move(str));
+                       str.clear();
                        ++ptr;
                        continue;
                }