Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yv6u0-0001BX-Bc for pgsql-bugs@arkaria.postgresql.org; Wed, 20 May 2015 16:31:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yv6tz-0007u3-Qp for pgsql-bugs@arkaria.postgresql.org; Wed, 20 May 2015 16:31:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yv6ty-0007sd-Ly for pgsql-bugs@postgresql.org; Wed, 20 May 2015 16:31:26 +0000 Received: from eu1sys200aog130.obsmtp.com ([207.126.144.203] helo=mail-wi0-f182.google.com) by magus.postgresql.org with smtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1Yv6tq-0006F6-V7 for pgsql-bugs@postgresql.org; Wed, 20 May 2015 16:31:25 +0000 Received: from mail-wi0-f182.google.com ([209.85.212.182]) (using TLSv1) by eu1sys200aob130.postini.com ([207.126.147.11]) with SMTP ID DSNKVVy20TtwMvr9Z5Akp5LsSqfq8YzdCl6c@postini.com; Wed, 20 May 2015 16:31:18 UTC Received: by wizk4 with SMTP id k4so161554061wiz.1 for ; Wed, 20 May 2015 09:31:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=lEITUiUCiwOJVsJsf8i9MVqZ0lIN3NNmNbp3HtXokyU=; b=e0fYPSCorwQ6723ELnvW1PJHpyeBVDTb5YdxvVgPmhYlTjAhG3Fs6wfKYQhCbMfk3e 5l6XK5MvYd98F6BTznNqzdvothtQHt/0/Ac2UPBVwQwgsbwGa2O5jIrhjB/2yuOuRouM 1BBFnN9wYlorqApKCPMhRQNt15lYri+byh1T10U8mU8Xc2ohKZKMkfzur9Y5KDc9p/FT MW8IAk1gJOxCtgkAvLdAok7e/OAM7THHHRwCvz+LXtWXEnKT+ChZpu3KhiKZZVaUQqr1 JbjfO5bUGTx8Yxkh5/9TacML+RJoUEIfw9rnZE1aMNg/I+t+NuOUj34XYOYhQDye91Jg 4vVA== X-Gm-Message-State: ALoCoQnuzdjB6Wb1eCnEKbScbp5AQMaEHdEcLr/Pf/k0GmbDd0TVfrcj6yfMqRevl/SKd6SB9JBB7mJ+HSv5K8Ny4Rf8sGBOee0VgwslfpqGnpEJ0cdfb7TFTMnb6DOVjQbKfzT1JIokX/f+0FbxUaFZFaf+mENiQA== X-Received: by 10.181.13.165 with SMTP id ez5mr22336246wid.77.1432139473369; Wed, 20 May 2015 09:31:13 -0700 (PDT) X-Received: by 10.181.13.165 with SMTP id ez5mr22336222wid.77.1432139473216; Wed, 20 May 2015 09:31:13 -0700 (PDT) Received: from ashulgin01.corp.ad.zalando.net ([94.135.236.132]) by mx.google.com with ESMTPSA id ha4sm4310561wib.0.2015.05.20.09.31.12 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 20 May 2015 09:31:12 -0700 (PDT) From: Oleksandr Shulgin To: Michael Paquier Cc: hlinnaka@iki.fi, Tom Lane , Pg Bugs Subject: Re: PQexec() hangs on OOM References: <547480DE.4040408@vmware.com> <25150.1428328002@sss.pgh.pa.us> <552427FC.6060302@iki.fi> <5526BA0A.4090600@iki.fi> Date: Wed, 20 May 2015 18:31:10 +0200 In-Reply-To: (Michael Paquier's message of "Fri, 10 Apr 2015 20:53:34 +0900") Message-ID: <87wq03rz1t.fsf@ashulgin01.corp.ad.zalando.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Michael Paquier writes: > >> There are still a few parseInput subroutines that have similar issues. In >> fe-protocol2.c: >> >> * pqGetErrorNotice2 returns EOF if there is not enough data, but also on >> OOM. The caller assumes it's because not enough data. >> * getRowDescriptions() is the same, although it sets conn->errorMessage on >> OOM. > > OK, I extended those two with the same logic as previously. > >> * getAnotherTuple() is the same, but it also skips over the received data, >> so you won't get stuck. So maybe that's OK. > > I think that it should be changed for consistency with the others, so > done this way for this function, and this way we only need to bail-out > if status == -2, a status of -1 meaning that there is not enough data. > >> * getNotify() just drops any NOTIFY messages on OOM. Perhaps that's OK.. > > This one is different though, it directly skips the messages. > >> The corresponding functions in fe-protocol3.c are pretty much identical, >> with the same issues. In addition: >> >> * getParameterStatus will act as if the parameter value was "out of memory". >> That'll be fun for something like client_encoding or >> standard_conforming_strings. Would be good to use a small char[100] >> variable, in stack, if it fits, and only use malloc for larger values. That >> would cover all the common variables that need to be machine-parsed. > > Are you suggesting to replace PQExpBuffer? > > So, attached is take three for all the other things above. There's still one call to pqGetErrorNotice3 that doesn't check returned value for -2, in fe-connect.c. Shouldn't we also check it like this: diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index e7c7a25..330b8da 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -2242,6 +2242,7 @@ keep_going: /* We will come back to here until there is int msgLength; int avail; AuthRequest areq; + int res; /* * Scan the message from current point (note that if we find @@ -2366,11 +2367,18 @@ keep_going: /* We will come back to here until there is { if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3) { - if (pqGetErrorNotice3(conn, true)) + res = pqGetErrorNotice3(conn, true); + if (res == -1) { /* We'll come back when there is more data */ return PGRES_POLLING_READING; } + else if (res == -2) + { + printfPQExpBuffer(&conn->errorMessage, + libpq_gettext("out of memory\n")); + goto error_return; + } } else { -- Alex -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs