From patchwork Thu Jun 15 18:24:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Greer X-Patchwork-Id: 9789811 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 358CA60325 for ; Thu, 15 Jun 2017 18:26:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EE5A2861E for ; Thu, 15 Jun 2017 18:26:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23DE62862C; Thu, 15 Jun 2017 18:26:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9FE12861E for ; Thu, 15 Jun 2017 18:26:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752231AbdFOS0S (ORCPT ); Thu, 15 Jun 2017 14:26:18 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:55597 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753184AbdFOSZa (ORCPT ); Thu, 15 Jun 2017 14:25:30 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 23E1320A78; Thu, 15 Jun 2017 14:25:19 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Thu, 15 Jun 2017 14:25:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=animalcreek.com; h=cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=Maw S5sn0C1fDTHK0+751nBY5ZGQ87Y4hMbeUz9eFFBY=; b=PiBdK27vvdcu+h+T+M9 hPMHUX5QwZg2/ru/RHvR1jfw2CpN6tw/hfG2Az1+mYSZdJburxGozLbb2AbBvh84 +nePkuPSCyG+wcIEYVb1WRSoRk78h+dr2149MfTTnT5oyTwx+EgeRtH4XmvRQgZ+ qxvJ3qg0XynGBGWv1pbPe3Fw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=MawS5sn0C1fDTHK0+751nBY5ZGQ87Y4hMbeUz9eFF BY=; b=qgvnVqfVM7J2m5XsLQ83Z/hd/Uo79n1DYCRgIYfIb0/2sG+Pceip/n63Q 1/hJCiUplpWjESWEGw2svGL2K1h/wBFLJbQmc648IhMpf/zmKwduQDcCqcAelwjG rAOVNTEYUva8qUWozEwnbv7IpOG2uwyc4Dm8l1FwymUW6Q2d/WkuwrW8CXs3CBzJ QyP3veb7+bKL06lfAJyDxfAr/emHD1e7kGqvFcllyDZqsf04RlUe8fJ9Qd0owA6o Y3apDzAmJsIBciFquziGPVo1RevAcTumFn6P49M552paVvDL8Zj+3Xbxe4/Dt2MC vyBLzuC5UAirBx3AlK9XhwnspT/Kw== X-ME-Sender: X-Sasl-enc: cu4ENZ0HqxBtBIymzYeOfZb1iq2kolhSpAZ35Boh6pK9 1497551118 Received: from blue.animalcreek.com (ip68-2-81-12.ph.ph.cox.net [68.2.81.12]) by mail.messagingengine.com (Postfix) with ESMTPA id D512E7E85D; Thu, 15 Jun 2017 14:25:18 -0400 (EDT) Received: from blue.animalcreek.com (localhost [127.0.0.1]) by blue.animalcreek.com (Postfix) with ESMTP id A3982A2053D; Thu, 15 Jun 2017 11:25:17 -0700 (MST) From: Mark Greer To: Samuel Ortiz Cc: linux-wireless@vger.kernel.org, linux-nfc@lists.01.org, Mark Greer Subject: [PATCH 06/23] ndef: Validate text data in WKT Text records Date: Thu, 15 Jun 2017 11:24:59 -0700 Message-Id: <20170615182516.4508-7-mgreer@animalcreek.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170615182516.4508-1-mgreer@animalcreek.com> References: <20170615182516.4508-1-mgreer@animalcreek.com> Organization: Animal Creek Technologies, Inc. Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ensure that the text encodings in WKT Text records are valid. Signed-off-by: Mark Greer --- src/ndef.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ndef.c b/src/ndef.c index 38dcf72..fb17be9 100644 --- a/src/ndef.c +++ b/src/ndef.c @@ -1149,8 +1149,9 @@ static struct near_ndef_text_payload * parse_text_payload(uint8_t *payload, uint32_t length) { struct near_ndef_text_payload *text_payload = NULL; - uint8_t status, lang_length; + uint8_t status, lang_length, len, *txt, *g_str; uint32_t offset; + gboolean valid; DBG(""); @@ -1185,9 +1186,26 @@ parse_text_payload(uint8_t *payload, uint32_t length) offset += lang_length; - if ((length - lang_length - 1) > 0) { - text_payload->data = g_strndup((char *)(payload + offset), - length - lang_length - 1); + len = length - lang_length - 1; + + if (len > 0) { + txt = payload + offset; + + if (status) + g_str = g_utf16_to_utf8((gunichar2 *)txt, len, NULL, + NULL, NULL); + else + g_str = txt; + + valid = g_utf8_validate(g_str, len, NULL); + + if (status) + g_free(g_str); + + if (!valid) + goto fail; + + text_payload->data = g_strndup(txt, len); } else { text_payload->data = NULL; }