Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXFSy-0003gI-7B for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Nov 2019 02:11:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXFSv-000496-IK for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Nov 2019 02:11:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXFSv-00048w-20 for pgsql-hackers@lists.postgresql.org; Wed, 20 Nov 2019 02:11:33 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iXFSr-0002wW-D3 for pgsql-hackers@postgresql.org; Wed, 20 Nov 2019 02:11:31 +0000 Received: by mail-pl1-x643.google.com with SMTP id bb5so13025172plb.4 for ; Tue, 19 Nov 2019 18:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=AKNg+yKJeUPjtr2z7YUL+Jw5itBcmwx/I98+dYhJ3hg=; b=cxBP2P0aEOUlQdsgn7URGTaecC7sxXpPRYAdzoxkFSWEDWDymEFIGhrB1d2PBzu7XX rjHsxhIksWrqsuFyT/uBC6aMzqROk8i4QsMCTk4MxUPlt9WAnIqNfssuz7SGCWSpryb9 Hl5o6Tpa3DfG0bYmpf4k8ZIKFRdY40/KCR/LAd1qN9ziNUdUE4WTmh71fEI7EAf4yCdt KCjnpHhtB75ya11XzVuvDSMZfVnbxFXxDjvbW1+U5dpzazJqFnHAZxRaaBZsvuFlcj3J Hfr0t+JXctQtfauH1cjz9Y1sd2jqZsuwRgsWYJV6Hpiwe/xzq/KpBKT9gU+7cWsC2gjW yo7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=AKNg+yKJeUPjtr2z7YUL+Jw5itBcmwx/I98+dYhJ3hg=; b=mnq3WS4gaVrURZ0y7MwE5eIVqPRq2ihPGt8X0QmoWBoJEF1sqtNB/p88DC61OXvoER UwAXZXQdcChZ5UoD6ydaF3iLw/8AcYcq6oiWmvnn8ZkfGiaLLjMkdCHcBjsN7ONLcV5r i4cn91IMLoRndYRlb7BE0gE1YJg2VprcK94j5hUVWE0rALJABmEvHcjO08GVWHnYMkKk kfH8E447nVYZhazJkm3AQ4Y/qgfcfRsav5A2yZyL2tCLQr2v5IuVAKoOGX5YD7PAs5Pi WPBtGSHQJKO1rK1+jrbachS0qwUWvHTE7O3+19iAp+fTd8iO+4NIDSmafidm0XEjPalr vDEA== X-Gm-Message-State: APjAAAVZ6oek7SwN3kmS7KVRyFgOEAN6hmR4rTV5TAzN7+NiB6IsyCbC hU96+Q8BQqb+rV5mjdKNHlc= X-Google-Smtp-Source: APXvYqzltwRcdn8yYxTvHawLBq+dvT5o/RnMXQjD1ZzZomjFLiIJd1gyUdu7bZ2K/6Air4FapHgQTw== X-Received: by 2002:a17:902:ba82:: with SMTP id k2mr394480pls.238.1574215888238; Tue, 19 Nov 2019 18:11:28 -0800 (PST) Received: from localhost (w199058.dynamic.ppp.asahi-net.or.jp. [121.1.199.58]) by smtp.gmail.com with ESMTPSA id x192sm29969422pfd.96.2019.11.19.18.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2019 18:11:27 -0800 (PST) Date: Wed, 20 Nov 2019 11:11:16 +0900 (JST) Message-Id: <20191120.111116.481406309940778474.horikyota.ntt@gmail.com> To: tgl@sss.pgh.pa.us Cc: andres@anarazel.de, vignesh21@gmail.com, pgsql-hackers@postgresql.org Subject: Re: initdb SegFault From: Kyotaro Horiguchi In-Reply-To: <19334.1574183210@sss.pgh.pa.us> References: <7379.1574176562@sss.pgh.pa.us> <20191119161059.6styj2huulh4zrkw@alap3.anarazel.de> <19334.1574183210@sss.pgh.pa.us> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk At Tue, 19 Nov 2019 12:06:50 -0500, Tom Lane wrote in > Andres Freund writes: > > Agreed wrt this specific failure scenario. It does however seem not > > great that callsites for PQExpBuffer ought to check every call for > > allocation failures, in the general case. > > It is possible to check just once at the end, using the PQExpBufferBroken > API, and I believe that libpq for instance is fairly careful about that. FWIW, I looked though the callers of PQExpBuffer. pqGetErrorNotice3 seems ingoring OOM on message buffer when !isError, then sets NULL to res->errMsg. getParameterStatus doesn't check that before use, too. Most of the callers of PQExpBufferDataBroken use libpq_gettext("out of memory"). And some of them do strdup(libpq_gettext()). Not restricting to libpq functions, dblink_connstr_check complains as "password is required" when PQconninfoParse hits OOM. libpqrcv_check_conninfo() will show '(null)' or maybe get SEGV on some platforms when PQconninfoParse() hits OOM, since it uses err without null checking. pg_basebackup, pg_dumpall and pg_isready is doing the same thing. > I agree that programs that just need to print something and exit could > perhaps ask pqexpbuffer.c to handle that for them. (But initdb still > doesn't fall in that category, because of its very nontrivial atexit > handler :-(.) > > > I wonder if, for frontend paths, a simplified error handling path would > > be worthwhile for OOM paths. Doing only a write() or such to print an > > error message. > > Perhaps. You wouldn't get any translation --- but then, gettext is > probably going to fail anyway under such conditions. I think we should refrain from translating in the cases. regards. -- Kyotaro Horiguchi NTT Open Source Software Center