Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rT6I3-000QNL-0c for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 20:25:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rT6I2-003MFw-7H for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 20:25:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rT6I1-003MF0-UC for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 20:25:33 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rT6Hz-003MCO-55 for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 20:25:32 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5f254d1a6daso73680297b3.2 for ; Thu, 25 Jan 2024 12:25:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1706214330; x=1706819130; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0NrMLrq+CjHQIN0Wk5GgW6PETG2UUQti4d4wITtqsHM=; b=K1a3tjTb/bqthEpmbCNLtM6zyWi5a5cHgPbeX9svQQwDS6ut2xpDdgHbtw09h1W/6x LicnmjbxXq2tAvT474HP5tMiu7bqrtbcggSuzR8uTFA7CFJ1f33agOzG00nYKh79Y80v FJhGjde7z8bU0xhAAqWH71cBVBHRgpZ9k1ZXujmlHNXnGEmMUcDACZ7O0xcUHF61nTSE tdyqIXpbo3EmW9IJ78cniROYvk3Dj6FZv48qMcIo2OF1HRXnsfAZ6FXYRCLgpnFG3khb uwatOdnenWsr8OLVXgcTxm1Y7KjMpeclGmhD1FOaZAhTck4eJtvEEVYWU8JW6EcDiiEq kiXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706214330; x=1706819130; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0NrMLrq+CjHQIN0Wk5GgW6PETG2UUQti4d4wITtqsHM=; b=X+nIOBjRiYqmr59gRpPxfH9KjENW9ITtvj0GqypDXh7pZAKGCvcJmc4Ht/Mkt4jxs6 ugsITwmnKf0RScOkkIQjzD4hV9NjCRRfF+2NAryBLWsyDI5EERjdbxhCb4ZmNHmfTvVL KQymMrLmfDgNCz61hpex79IVcNqXl1gSR/q/FaidZOjGUMbsxDUM6vS1wU+cnd4pk3Za ZdA0sHOatCWFlND5CI7z6sJYy9tusdC/FgXL/jF6ESTrk4sGBG/KxsI/SPq9Kd59+pHj 7JqV9pyaA5bjYurv9mIYuFVOtHW5wWS2M6mXrdSU7mv9N+UuG0ugOF1YcZAqhN4iK6Oa nbHQ== X-Gm-Message-State: AOJu0YyrOZcpAIMd340R2zX9eQas0mv+YNbVqiZ/xugReLBqCDCRpdx6 Mq8JMUKaXBSJ69ieWnVi32dReJiVJUxPo6NrDQSVRuU1QlOh60W12KG4WQHAoZg= X-Google-Smtp-Source: AGHT+IH55z9/LRq3fPednEyMoC6hk0Q1o1GurRewIhFnfRPISKLoCX7nR5pF3AvRCIoHTq6auw/yDQ== X-Received: by 2002:a81:d44d:0:b0:5ff:acde:158d with SMTP id g13-20020a81d44d000000b005ffacde158dmr377377ywl.32.1706214329693; Thu, 25 Jan 2024 12:25:29 -0800 (PST) Received: from ?IPV6:2605:a601:91f3:1900::2bb? ([2605:a601:91f3:1900::2bb]) by smtp.googlemail.com with ESMTPSA id de29-20020a05620a371d00b007835c9bf30csm5351261qkb.83.2024.01.25.12.25.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jan 2024 12:25:29 -0800 (PST) Message-ID: Date: Thu, 25 Jan 2024 15:25:28 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: More new SQL/JSON item methods Content-Language: en-US To: Tom Lane Cc: Jeevan Chalke , Peter Eisentraut , PostgreSQL Hackers References: <1d092c02-8249-4e56-8b8e-ae4db95b8fde@eisentraut.org> <5d37428e-0753-e721-8e77-81cc4d0dc9f1@dunslane.net> <439811.1706211069@sss.pgh.pa.us> From: Andrew Dunstan In-Reply-To: <439811.1706211069@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-01-25 Th 14:31, Tom Lane wrote: > Andrew Dunstan writes: >> Thanks, I have pushed this. > The buildfarm is pretty widely unhappy, mostly failing on > > select jsonb_path_query('1.23', '$.string()'); > > On a guess, I tried running that under valgrind, and behold it said > > ==00:00:00:05.637 435530== Conditional jump or move depends on uninitialised value(s) > ==00:00:00:05.637 435530== at 0x8FD131: executeItemOptUnwrapTarget (jsonpath_exec.c:1547) > ==00:00:00:05.637 435530== by 0x8FED03: executeItem (jsonpath_exec.c:626) > ==00:00:00:05.637 435530== by 0x8FED03: executeNextItem (jsonpath_exec.c:1604) > ==00:00:00:05.637 435530== by 0x8FCA58: executeItemOptUnwrapTarget (jsonpath_exec.c:956) > ==00:00:00:05.637 435530== by 0x8FFDE4: executeItem (jsonpath_exec.c:626) > ==00:00:00:05.637 435530== by 0x8FFDE4: executeJsonPath.constprop.30 (jsonpath_exec.c:612) > ==00:00:00:05.637 435530== by 0x8FFF8C: jsonb_path_query_internal (jsonpath_exec.c:438) > > It's fairly obviously right about that: > > JsonbValue jbv; > ... > jb = &jbv; > Assert(tmp != NULL); /* We must have set tmp above */ > jb->val.string.val = (jb->type == jbvString) ? tmp : pstrdup(tmp); > ^^^^^^^^^^^^^^^^^^^^^ > > Presumably, this is a mistaken attempt to test the type > of the thing previously pointed to by "jb". > > On the whole, what I'd be inclined to do here is get rid > of this test altogether and demand that every path through > the preceding "switch" deliver a value that doesn't need > pstrdup(). The only path that doesn't do that already is > > case jbvBool: > tmp = (jb->val.boolean) ? "true" : "false"; > break; > > and TBH I'm not sure that we really need a pstrdup there > either. The constants are immutable enough. Is something > likely to try to pfree the pointer later? I tried > > @@ -1544,7 +1544,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, > > jb = &jbv; > Assert(tmp != NULL); /* We must have set tmp above */ > - jb->val.string.val = (jb->type == jbvString) ? tmp : pstrdup(tmp); > + jb->val.string.val = tmp; > jb->val.string.len = strlen(jb->val.string.val); > jb->type = jbvString; > > and that quieted valgrind for this particular query and still > passes regression. Your fix looks sane. I also don't see why we need the pstrdup. > > (The reported crashes seem to be happening later during a > recursive invocation, seemingly because JsonbType(jb) is > returning garbage. So there may be another bug after this one.) > > I don't think so. AIUI The first call deals with the '$' and the second one deals with the '.string()', which is why we see the error on the second call. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com