• Bug#1108915: unblock: pdns/4.9.7-1 [pre-approval] (4/6)

    From Chris Hofstaedtler@1:229/2 to All on Tue Jul 8 09:30:02 2025
    [continued from previous message]

    throw DBException("attempting to start nested transaction without open parent env");
    }
    shard.env = getMDBEnv((getArg("filename") + "-" + std::to_string(id % s_shards)).c_str(),
    - MDB_NOSUBDIR | d_asyncFlag, 0600);
    + MDB_NOSUBDIR | d_asyncFlag, 0600, d_mapsize);
    shard.dbi = shard.env->openDB("records_v5", MDB_CREATE);
    }

    @@ -1405,10 +1405,7 @@
    d_matchkey = co(di.id);

    MDBOutVal key, val;
    - auto a = d_getcursor->lower_bound(d_matchkey, key, val);
    - auto b0 = key.getNoStripHeader<StringView>();
    - auto b = b0.rfind(d_matchkey, 0);
    - if (a || b != 0) {
    + if (d_getcursor->prefix(d_matchkey, key, val) != 0) {
    d_getcursor.reset();
    }

    @@ -1470,7 +1467,7 @@
    d_matchkey = co(zoneId, relqname, type.getCode());
    }

    - if (d_getcursor->lower_bound(d_matchkey, key, val) || key.getNoStripHeader<StringView>().rfind(d_matchkey, 0) != 0) {
    + if (d_getcursor->prefix(d_matchkey, key, val) != 0) {
    d_getcursor.reset();
    if (d_dolog) {
    g_log << Logger::Warning << "Query " << ((long)(void*)this) << ": " << d_dtime.udiffNoReset() << " us to execute (found nothing)" << endl;
    @@ -1508,7 +1505,7 @@

    if (zr.dr.d_type == QType::NSEC3) {
    // Hit a magic NSEC3 skipping
    - if (d_getcursor->next(d_currentKey, d_currentVal) || d_currentKey.getNoStripHeader<StringView>().rfind(d_matchkey, 0) != 0) {
    + if (d_getcursor->next(d_currentKey, d_currentVal) != 0) {
    // cerr<<"resetting d_getcursor 1"<<endl;
    d_getcursor.reset();
    }
    @@ -1536,7 +1533,7 @@

    if (d_currentrrsetpos >= d_currentrrset.size()) {
    d_currentrrset.clear(); // will invalidate lrr
    - if (d_getcursor->next(d_currentKey, d_currentVal) || d_currentKey.getNoStripHeader<StringView>().rfind(d_matchkey, 0) != 0) {
    + if (d_getcursor->next(d_currentKey, d_currentVal) != 0) {
    // cerr<<"resetting d_getcursor 2"<<endl;
    d_getcursor.reset();
    }
    @@ -2423,7 +2420,7 @@

    auto cursor = txn->txn->getCursor(txn->db->dbi);
    MDBOutVal key, val;
    - if (cursor.lower_bound(matchkey, key, val)) {
    + if (cursor.prefix(matchkey, key, val) != 0) {
    // cout << "Could not find anything"<<endl;
    return false;
    }
    @@ -2431,7 +2428,7 @@
    bool hasOrderName = !ordername.empty();
    bool needNSEC3 = hasOrderName;

    - for (; key.getNoStripHeader<StringView>().rfind(matchkey, 0) == 0;) {
    + do {
    vector<LMDBResourceRecord> lrrs;

    if (co.getQType(key.getNoStripHeader<StringView>()) != QType::NSEC3) { >> @@ -2456,9 +2453,7 @@
    }
    }

    - if (cursor.next(key, val))
    - break;
    - }
    + } while (cursor.next(key, val) == 0);

    bool del = false;
    LMDBResourceRecord lrr;
    diff -Nru pdns-4.9.4/modules/lmdbbackend/lmdbbackend.hh pdns-4.9.7/modules/lmdbbackend/lmdbbackend.hh
    --- pdns-4.9.4/modules/lmdbbackend/lmdbbackend.hh 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/modules/lmdbbackend/lmdbbackend.hh 2025-07-07 09:42:15.000000000 +0200
    @@ -333,4 +333,5 @@
    bool d_random_ids;
    bool d_handle_dups;
    DTime d_dtime; // used only for logging
    + uint64_t d_mapsize;
    };
    diff -Nru pdns-4.9.4/pdns/credentials.hh pdns-4.9.7/pdns/credentials.hh
    --- pdns-4.9.4/pdns/credentials.hh 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/pdns/credentials.hh 2025-07-07 09:42:15.000000000 +0200
    @@ -21,7 +21,7 @@
    */
    #pragma once

    -#include <memory>
    +#include <cstdint>
    #include <string>

    class SensitiveData
    diff -Nru pdns-4.9.4/pdns/dnssecinfra.cc pdns-4.9.7/pdns/dnssecinfra.cc
    --- pdns-4.9.4/pdns/dnssecinfra.cc 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/pdns/dnssecinfra.cc 2025-07-07 09:42:15.000000000 +0200
    @@ -782,7 +782,7 @@
    DNSPacketWriter dw(signVect, DNSName(), 0);
    auto pos=signVect.size();
    if(!timersonly) {
    - dw.xfrName(tsigKeyName, false);
    + dw.xfrName(tsigKeyName.makeLowerCase(), false);
    dw.xfr16BitInt(QClass::ANY); // class
    dw.xfr32BitInt(0); // TTL
    dw.xfrName(trc.d_algoName.makeLowerCase(), false);
    diff -Nru pdns-4.9.4/pdns/lua-record.cc pdns-4.9.7/pdns/lua-record.cc
    --- pdns-4.9.4/pdns/lua-record.cc 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/pdns/lua-record.cc 2025-07-07 09:42:15.000000000 +0200
    @@ -915,81 +915,87 @@
    return std::string("error");
    });
    lua.writeFunction("createForward", []() {
    - static string allZerosIP("0.0.0.0");
    - DNSName rel=s_lua_record_ctx->qname.makeRelative(s_lua_record_ctx->zone);
    - // parts is something like ["1", "2", "3", "4", "static"] or
    - // ["1", "2", "3", "4"] or ["ip40414243", "ip-addresses", ...]
    - auto parts = rel.getRawLabels();
    - // Yes, this still breaks if an 1-2-3-4.XXXX is nested too deeply... >> - if(parts.size()>=4) {
    - try {
    - ComboAddress ca(parts[0]+"."+parts[1]+"."+parts[2]+"."+parts[3]); >> - return ca.toString();
    - } catch (const PDNSException &e) {
    - return allZerosIP;
    - }
    - } else if (!parts.empty()) {
    - auto& input = parts.at(0);
    -
    - // allow a word without - in front, as long as it does not contain anything that could be a number
    - size_t nonhexprefix = strcspn(input.c_str(), "0123456789abcdefABCDEF");
    - if (nonhexprefix > 0) {
    - input = input.substr(nonhexprefix);
    - }
    -
    - // either hex string, or 12-13-14-15
    - vector<string> ip_parts;
    -
    - stringtok(ip_parts, input, "-");
    - unsigned int x1, x2, x3, x4;
    - if (ip_parts.size() >= 4) {
    - // 1-2-3-4 with any prefix (e.g. ip-foo-bar-1-2-3-4)
    - string ret;
    - for (size_t index=4; index > 0; index--) {
    - auto octet = ip_parts[ip_parts.size() - index];
    - try {
    - auto octetVal = std::stol(octet);
    + static string allZerosIP{"0.0.0.0"};
    + try {
    + DNSName rel{s_lua_record_ctx->qname.makeRelative(s_lua_record_ctx->zone)};
    +
    + // parts is something like ["1", "2", "3", "4", "static"] or
    + // ["1", "2", "3", "4"] or ["ip40414243", "ip-addresses", ...]
    + auto parts = rel.getRawLabels();
    + // Yes, this still breaks if an 1-2-3-4.XXXX is nested too deeply...
    + if (parts.size() >= 4) {
    + ComboAddress address(parts[0]+"."+parts[1]+"."+parts[2]+"."+parts[3]);
    + return address.toString();
    + }
    + if (!parts.empty()) {
    + auto& input = parts.at(0);
    +
    + // allow a word without - in front, as long as it does not contain anything that could be a number
    + size_t nonhexprefix = strcspn(input.c_str(), "0123456789abcdefABCDEF");
    + if (nonhexprefix > 0) {
    + input = input.substr(nonhexprefix);
    + }
    +
    + // either hex string, or 12-13-14-15
    + vector<string> ip_parts;
    +
    + stringtok(ip_parts, input, "-");

    [continued in next message]

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)