Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pG2Z8-0001ZU-Cz for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jan 2023 18:44:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pG2Z6-0005Fn-VN for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jan 2023 18:44:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pG2Z6-0005DT-Jo for pgsql-hackers@lists.postgresql.org; Thu, 12 Jan 2023 18:44:40 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pG2Z4-0007K8-9r for pgsql-hackers@postgresql.org; Thu, 12 Jan 2023 18:44:40 +0000 Received: by mail-pl1-x635.google.com with SMTP id v23so16195322plo.1 for ; Thu, 12 Jan 2023 10:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kZnum9JaGxhS5DBswHMDHt1CnFaBVaF2ZpAFN8QzJng=; b=Smuz2sKpDZGWS1q/jDN/fEZvz8t2jHHBz1oq/Yf4hJzE28oSrDqgNJYtcvGl9JiLnJ mb5lElsjhHcZYAAgEpAIM0QTof+/81QEw8/CVnrdMe+E/qeTXQiNljtutpr+MryCA6lR t8t7xS5TfjDoE1xSU7ueFmvKx+8313pZj/3DLrICju2Tiq4cCItbSatZ1NgiyH51vEj/ Ria+YCjHc89utmj0dtuAmaAHFf8KAIkLab0Alljpt9LPxFqSTj6WqVQ4AAyq6yoG5clF b03Ol5UndLNCE8q5yxUtjqUh+cuDFb+Rfw1psqUOBwaOoAKwYdjLqnjaMeTnyg6c9hpa PDXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kZnum9JaGxhS5DBswHMDHt1CnFaBVaF2ZpAFN8QzJng=; b=v1lb2B8AWIBw5RAx3zVZMVtoRLtcmwMQLzsKrU9icRhPEkVkusc5k2O85dGrNO4cWU 5Sy3ADsG4+TP6SHyVgW8w8tuqCk7ZJodJXA6AuvzK5IF6Yt50qpc3ynz6R/TAZpIauX1 hBzLImrnUFfKfbnzbaFXJzEvOYfr3LaZdjIyDLa24ZFBJZ74JxqzP/v7eHz+Ujse/ey5 UE+lBD29CANBE2yFBnIrCzhzFbC0Rb/olVKybhctpu+clVRfJ/NOj4m2EX6PCzWbNcBq PY0j3NKuaNIy36J14jWkH7A9Z/Joc4mV2QLfAk49YK4DdZiOU+x6SNkm+UA8Hc6bjrmW 4qPQ== X-Gm-Message-State: AFqh2koj36Rd9gUUiGH0URYLR5ERNyinjqGFK1JAjPDbjeXORntcFUc0 G0jRUBol5EQUZDsHjfzfVgyaltS9DVo= X-Google-Smtp-Source: AMrXdXveZrlM2et9o+hEgnxDW4FjcmOQbMh9zq2BiOdQJf71azIhjhb6ye4qsJ+sQKwczAKyAdbzaQ== X-Received: by 2002:a17:902:d305:b0:192:b2b5:f6b9 with SMTP id b5-20020a170902d30500b00192b2b5f6b9mr47934391plc.50.1673549075992; Thu, 12 Jan 2023 10:44:35 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id j16-20020a170902da9000b001769206a766sm12459110plx.307.2023.01.12.10.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 10:44:35 -0800 (PST) Date: Thu, 12 Jan 2023 10:44:33 -0800 From: Nathan Bossart To: Xing Guo Cc: pgsql-hackers@postgresql.org Subject: Re: PL/Python: Fix return in the middle of PG_TRY() block. Message-ID: <20230112184433.GA2104952@nathanxps13> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 12, 2023 at 11:19:29PM +0800, Xing Guo wrote: > I was running static analyser against PostgreSQL and found there're 2 > return statements in PL/Python module which is not safe. Patch is > attached. Is the problem that PG_exception_stack and error_context_stack aren't properly reset? > @@ -690,12 +690,12 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r > PyObject *volatile pltdata = NULL; > char *stroid; > > + pltdata = PyDict_New(); > + if (!pltdata) > + return NULL; > + > PG_TRY(); > { > - pltdata = PyDict_New(); > - if (!pltdata) > - return NULL; > - > pltname = PLyUnicode_FromString(tdata->tg_trigger->tgname); > PyDict_SetItemString(pltdata, "name", pltname); > Py_DECREF(pltname); There's another "return" later on in this PG_TRY block. I wonder if it's possible to detect this sort of thing at compile time. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com