From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754758AbcCBXuC (ORCPT ); Wed, 2 Mar 2016 18:50:02 -0500 Received: from mail-wm0-f43.google.com ([74.125.82.43]:34937 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754449AbcCBXt5 (ORCPT ); Wed, 2 Mar 2016 18:49:57 -0500 From: Rasmus Villemoes To: Jessica Yu Cc: Andrew Morton , Andy Shevchenko , Kees Cook , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] sscanf: implement basic character sets Organization: D03 References: <1456518059-7472-1-git-send-email-jeyu@redhat.com> Date: Thu, 03 Mar 2016 00:49:53 +0100 In-Reply-To: <1456518059-7472-1-git-send-email-jeyu@redhat.com> (Jessica Yu's message of "Fri, 26 Feb 2016 15:20:59 -0500") Message-ID: <87r3fs4ezi.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 26 2016, Jessica Yu wrote: > @@ -2714,6 +2718,57 @@ int vsscanf(const char *buf, const char *fmt, va_list args) > num++; > } > continue; > + /* > + * Warning: This implementation of the '[' conversion specifier > + * deviates from its glibc counterpart in the following ways: > + * (1) It does NOT support ranges i.e. '-' is NOT a special character > + * (2) It cannot match the closing bracket ']' itself > + * (3) A field width is required > + * (4) '%*[' (discard matching input) is currently not supported > + * > + * Example usage: > + * ret = sscanf("00:0a:95","%2[^:]:%2[^:]:%2[^:]", buf1, buf2, buf3); > + * if (ret < 3) > + * // etc.. > + */ > + case '[': > + { > + char *s = (char *)va_arg(args, char *); > + DECLARE_BITMAP(set, 256) = {0}; > + unsigned int len = 0; > + bool negate = (*fmt == '^'); > + > + /* field width is required */ > + if (field_width == -1) > + return num; > + > + if (negate) > + ++fmt; > + > + for ( ; *fmt && *fmt != ']'; ++fmt, ++len) > + set_bit((u8)*fmt, set); > + > + /* no ']' or no character set found */ > + if (!*fmt || !len) > + return num; > + ++fmt; > + I think it might be useful to be able to do [^] to match any sequence of characters. If the user passed [] the code below won't match anything, so we'll return num anyway. In other words, I'd just omit the test for empty character set. Other than that, LGTM. Rasmus