From patchwork Thu Jul 4 01:16:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Oester X-Patchwork-Id: 256773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 29DE62C00AD for ; Thu, 4 Jul 2013 11:16:21 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933176Ab3GDBQP (ORCPT ); Wed, 3 Jul 2013 21:16:15 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:40807 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932143Ab3GDBQN (ORCPT ); Wed, 3 Jul 2013 21:16:13 -0400 Received: by mail-pa0-f50.google.com with SMTP id fb1so777824pad.37 for ; Wed, 03 Jul 2013 18:16:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent:x-gm-message-state; bh=GQg/34XgcwW4p/nIZTsI8HtS/N+coGHJiiXcsSdBmZ4=; b=ngN8i/ulBci+ooMpNDDasRPcQF+seoT4zTIQPbTIxRN+Ytt/vNfdSd9w/OREXAjg6m o9IoMtAYjCEb8DzbC0p5+SygJ2oIeUL2XegbH2Kr7c0S7AmqCH54Do13jQhMB7HTXfKl +8DplIfYlp4BAVb7SBKp36xzrdyjUYh56Nf7eGNCXmYBbI8JMo378Jp4XHwIZDoy9oz7 NEPStV/vdyuHeO3Hf5YU4awElgraDUfxfVPj61NvOVlnh+MMbfNlZD8l7ZXAcB/x/1l+ /Zz4fg2SOdYPENDd2PzOjkreDZdlMsIGkAp9ETbVqh0oXT0pr59d7k58MBwF4dB+WwXj /a4g== X-Received: by 10.68.143.73 with SMTP id sc9mr3345257pbb.2.1372900573398; Wed, 03 Jul 2013 18:16:13 -0700 (PDT) Received: from linuxace.com (cpe-76-171-169-87.socal.res.rr.com. [76.171.169.87]) by mx.google.com with ESMTPSA id iv4sm548303pbc.9.2013.07.03.18.16.11 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Jul 2013 18:16:12 -0700 (PDT) Date: Wed, 3 Jul 2013 18:16:10 -0700 From: Phil Oester To: netfilter-devel@vger.kernel.org Cc: pablo@netfilter.org Subject: [PATCH] iptables: set errno correctly in iptcc_chain_index_alloc Message-ID: <20130704011610.GA9791@linuxace.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQm82FtRlfTfO1rdqVNp6kFyW6Fsh9cNLKiQbsWT3ClVrW3kD1qmbfIbqJ+Qmdk3VG/KphZ9 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org As reported by Robert Barnhardt, iptcc_chain_index_alloc does not populate errno with the appropriate ENOMEM on allocation failures. This causes incorrect error messages to be passed back to user such as "can't initialize iptables table 'X'" even if the issue was caused by OOM condition. Fix this by passing back ENOMEM if allocation failure occurs. This closes bugzilla #619. Phil Signed-off-by: Phil Oester diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c index f0f7815..004b0ec 100644 --- a/libiptc/libiptc.c +++ b/libiptc/libiptc.c @@ -502,7 +502,8 @@ static int iptcc_chain_index_alloc(struct xtc_handle *h) h->chain_index = malloc(array_mem); if (h->chain_index == NULL && array_mem > 0) { h->chain_index_sz = 0; - return -ENOMEM; + errno = ENOMEM; + return -1; } memset(h->chain_index, 0, array_mem); h->chain_index_sz = array_elems;