From patchwork Thu Nov 8 19:43:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Stewart X-Patchwork-Id: 197908 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 836E52C00AA for ; Fri, 9 Nov 2012 12:52:00 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 285229C17F; Thu, 8 Nov 2012 20:51:57 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3ijyMEGKIYbR; Thu, 8 Nov 2012 20:51:56 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CC1869C17A; Thu, 8 Nov 2012 20:51:51 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id B99BD9C17A for ; Thu, 8 Nov 2012 20:51:50 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SkCgaWq3mvto for ; Thu, 8 Nov 2012 20:51:46 -0500 (EST) Received: from mail-la0-f74.google.com (mail-la0-f74.google.com [209.85.215.74]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id B06B09C165 for ; Thu, 8 Nov 2012 20:51:46 -0500 (EST) Received: by mail-la0-f74.google.com with SMTP id j13so224101lah.5 for ; Thu, 08 Nov 2012 17:51:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:date:subject:to:message-id:x-gm-message-state; bh=/w9BYck8MW04vA3J0btFDDq7po6LRTIDF47KtTeTH5E=; b=iyw4OF41uqIikaNzHSoMi+XiinemTbspSSeiOmdYyoD+CfyTK04ueZrXZAGsjcxeFP LX1VH+JVqCZBEumch4dPEicoQSXH9+Gpj7TTSW1sgasBsrfrm5+fn8Tz3ex1BdXx9VNL jVHuhxFaCiZtLZorM5S9u7O++O1oVD5VpldI5xWiyNeP+87oQ4qGU52oGXFTikQaiTdl vMDknfEmtJreBpaAvA9QBOGoJdynsaAr3HgkclrIs+3VAyGr9ib/SIQK16wID9EQjKYZ NTvvSewjLsjED/bXdn14BP3wTZ0cD5kWq1lbXPhdcPFVQRnh2LcDq7FBdTwvZJvye4CK VIcg== Received: by 10.14.204.3 with SMTP id g3mr10898160eeo.7.1352425901159; Thu, 08 Nov 2012 17:51:41 -0800 (PST) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id z47si5677440eel.0.2012.11.08.17.51.41 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 08 Nov 2012 17:51:41 -0800 (PST) Received: from clearcreek.mtv.corp.google.com (clearcreek.mtv.corp.google.com [172.22.73.104]) by hpza9.eem.corp.google.com (Postfix) with ESMTP id 8AEED5C0050 for ; Thu, 8 Nov 2012 17:51:40 -0800 (PST) Received: by clearcreek.mtv.corp.google.com (Postfix, from userid 110058) id D066B200501; Thu, 8 Nov 2012 17:51:39 -0800 (PST) From: Paul Stewart Date: Thu, 8 Nov 2012 11:43:19 -0800 Subject: [PATCH] new_dbus_handlers: Clear errno To: hostap@lists.shmoo.com Message-Id: <20121109015139.D066B200501@clearcreek.mtv.corp.google.com> X-Gm-Message-State: ALoCoQmBF7anjom4y6/fkGbxtze7Uha2LRQfi/R9tqCwHzNDnfiMbJG//56kiSl8ilEHRgHPtPiHilRLZom+1NelTylmcsZ94r0+PHRykv7gf90uGADtUz8gh1looAVfpIn/L9fTnc8l1oQTzTONX/S7PwjP/ZEAUqU4lti1MVALesPQIHwh2qRBEcqn5K4WK+UniIXXTfrBami9dI3ZQ2SaXVOFXq/ZhQ== X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com There are a few instances where dbus handlers test the value of errno to test whether strtoul completes successfully. Since strtoul does not clear errno, and there's no strong reason to suspect that errno is already clear, it is safer to clear it right before calling strtoul. Also, any failure in strtoul (setting errno non-zero) should be considered a failure. While testing using dbus-send, I found that a malformed network path can cause a crash due to net_id being left NULL. We should test for this before calling strtoul on it. Tested with: dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \ /fi/w1/wpa_supplicant1/Interfaces/0 \ org.freedesktop.DBus.Properties.Get \ string:fi.w1.wpa_supplicant1.Interface string:Networks dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \ /fi/w1/wpa_supplicant1/Interfaces/0 \ fi.w1.wpa_supplicant1.Interface.RemoveNetwork \ objpath:/fi/w1/wpa_supplicant1/Interfaces/0/Networks/0 dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \ /fi/w1/wpa_supplicant1/Interfaces/0 \ fi.w1.wpa_supplicant1.Interface.RemoveNetwork \ objpath:/fi/w1/wpa_supplicant1/Interfaces/0/Networks/0 dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply \ /fi/w1/wpa_supplicant1/Interfaces/0 \ fi.w1.wpa_supplicant1.Interface.RemoveNetwork \ objpath:/fi/w1/wpa_supplicant1/Interfaces/0 Signed-hostap: Paul Stewart --- wpa_supplicant/dbus/dbus_new_handlers.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index e100df2..65f7226 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -1492,13 +1492,15 @@ DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message, /* Extract the network ID and ensure the network */ /* is actually a child of this interface */ iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL); - if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) { + if (iface == NULL || net_id == NULL || + os_strcmp(iface, wpa_s->dbus_new_path) != 0) { reply = wpas_dbus_error_invalid_args(message, op); goto out; } + errno = 0; id = strtoul(net_id, NULL, 10); - if (errno == EINVAL) { + if (errno != 0) { reply = wpas_dbus_error_invalid_args(message, op); goto out; } @@ -1592,13 +1594,15 @@ DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message, /* Extract the network ID and ensure the network */ /* is actually a child of this interface */ iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL); - if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) { + if (iface == NULL || net_id == NULL || + os_strcmp(iface, wpa_s->dbus_new_path) != 0) { reply = wpas_dbus_error_invalid_args(message, op); goto out; } + errno = 0; id = strtoul(net_id, NULL, 10); - if (errno == EINVAL) { + if (errno != 0) { reply = wpas_dbus_error_invalid_args(message, op); goto out; } @@ -1647,13 +1651,15 @@ DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message, /* Extract the network ID and ensure the network */ /* is actually a child of this interface */ iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL); - if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) { + if (iface == NULL || net_id == NULL || + os_strcmp(iface, wpa_s->dbus_new_path) != 0) { reply = wpas_dbus_error_invalid_args(message, op); goto out; } + errno = 0; id = strtoul(net_id, NULL, 10); - if (errno == EINVAL) { + if (errno != 0) { reply = wpas_dbus_error_invalid_args(message, net_id); goto out; }