From patchwork Wed Jul 2 13:20:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 4465501 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E7FAABEEAA for ; Wed, 2 Jul 2014 13:23:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08BC1202F8 for ; Wed, 2 Jul 2014 13:23:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BD7820351 for ; Wed, 2 Jul 2014 13:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753994AbaGBNWu (ORCPT ); Wed, 2 Jul 2014 09:22:50 -0400 Received: from mga03.intel.com ([143.182.124.21]:22494 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752712AbaGBNUg (ORCPT ); Wed, 2 Jul 2014 09:20:36 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 02 Jul 2014 06:20:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,588,1400050800"; d="scan'208";a="452518119" Received: from smile.fi.intel.com ([10.237.72.73]) by azsmga001.ch.intel.com with ESMTP; 02 Jul 2014 06:20:33 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1X2KSd-00050o-Gh; Wed, 02 Jul 2014 16:20:31 +0300 From: Andy Shevchenko To: "John W. Linville" , Johannes Berg , devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Andrew Morton Cc: Andy Shevchenko Subject: [PATCH 3/6] lib80211: re-use string_escape_mem_any_np() Date: Wed, 2 Jul 2014 16:20:26 +0300 Message-Id: <1404307229-19186-4-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1404307229-19186-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1404307229-19186-1-git-send-email-andriy.shevchenko@linux.intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In kernel we have function to escape a given string. Let's use it instead of custom approach. This fixes a bug. The current implementation wrongly prints octal numbers: only two first digits are used in case when 3 are required and the rest of the string ends up cut off. Additionally the \f, \v, \a, and \e are escaped to their alphabetic representation. It's safe to do since the print_ssid() is currently used for messaging only. Signed-off-by: Andy Shevchenko --- net/wireless/lib80211.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c index a55c27b..0c2f67b 100644 --- a/net/wireless/lib80211.c +++ b/net/wireless/lib80211.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -48,31 +49,10 @@ static void lib80211_crypt_deinit_handler(unsigned long data); const char *print_ssid(char *buf, const char *ssid, u8 ssid_len) { - const char *s = ssid; char *d = buf; ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN); - while (ssid_len--) { - if (isprint(*s)) { - *d++ = *s++; - continue; - } - - *d++ = '\\'; - if (*s == '\0') - *d++ = '0'; - else if (*s == '\n') - *d++ = 'n'; - else if (*s == '\r') - *d++ = 'r'; - else if (*s == '\t') - *d++ = 't'; - else if (*s == '\\') - *d++ = '\\'; - else - d += snprintf(d, 3, "%03o", *s); - s++; - } + d += string_escape_mem_any_np(ssid, ssid_len, buf, ~0UL, NULL); *d = '\0'; return buf; }