Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3902771pxy; Tue, 4 May 2021 12:34:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyCgarHcF8Gt5M42KYwNgn2dr74SoMh3KOcDewcOupPo/wbwxOK8qIh8M4Yr7S4aOWKLB+ X-Received: by 2002:a05:6402:3104:: with SMTP id dc4mr26986269edb.144.1620156873780; Tue, 04 May 2021 12:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620156873; cv=none; d=google.com; s=arc-20160816; b=elp6eRxKJeUZXs8FiKGS1qHp6ChAf3pkg+G1QjAe+WDfWx8OiabIu5z3DSS4MVY3e7 37Bd8bufOhjY6p+N9bJxH82v0l0pgR6q6Qe6H8t8DKko90qOrFSC6aphgme9a2qj1wiu tvQuTOxgxMeotOnnjN0x9FPEG21WJIEbcboYcbkK78+rIzMRhXGsCMUwz3V4FuSv+qKT NUFwQZiFDHQixk+skxpeDgsR9AO/50l7D0K9bEISbXj7dPbUHmLuXnVEo77cwYrF/OEw SQ01B0IyA++mnJvkEQbK+1BJ6ssfVAuQ2IVUveHwc8/4lk2x6+mdQuJHmDfgnw+idcm1 mzkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:organization:date:subject:to:from :message-id:dkim-signature; bh=dpukU8GguUO6xvcNrar3i7J3K9bMQJqkS5L6BNfPCBg=; b=T/yetkP9Zy9qejZQqdV0BjZTGLwOlpa4CadgVyjUK/qw5cwQks3OZuYX5PTZpqlZgM KREok/SZm30MVxuFWGTARIPpszOAO6KRJ7ciE3uDrJ2/XvpLQL7/xSdpk1XIP7/ISadx I6yUHble88mX4K39A/07/n/pLl/3MCZd8x737tNxdpZQpy2BSU173sGkNWSsnR2vyc8j YNYhFf2kR4NJp/iv9mqlfRejGyupx4l7pgxcuo/Y9DrcOZyg3zS2XT4XPTjPmFhsq9B2 3rPw66zSY0rhSM0sz4337HvwWZJBO4z/QPQx5L2S99R0AnTCm1qU8ppmGxkAIYFWyHAC ToCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arcor.de header.s=vfde-smtpout-mb-15sep header.b=Mbnohlt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si3563682ejy.319.2021.05.04.12.34.08; Tue, 04 May 2021 12:34:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@arcor.de header.s=vfde-smtpout-mb-15sep header.b=Mbnohlt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232153AbhEDTbi (ORCPT + 99 others); Tue, 4 May 2021 15:31:38 -0400 Received: from smtpout2.vodafonemail.de ([145.253.239.133]:34006 "EHLO smtpout2.vodafonemail.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbhEDTbi (ORCPT ); Tue, 4 May 2021 15:31:38 -0400 X-Greylist: delayed 497 seconds by postgrey-1.27 at vger.kernel.org; Tue, 04 May 2021 15:31:37 EDT Received: from smtp.vodafone.de (smtpa07.fra-mediabeam.com [10.2.0.38]) by smtpout2.vodafonemail.de (Postfix) with ESMTP id C777C120B8D for ; Tue, 4 May 2021 21:22:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arcor.de; s=vfde-smtpout-mb-15sep; t=1620156144; bh=dpukU8GguUO6xvcNrar3i7J3K9bMQJqkS5L6BNfPCBg=; h=From:To:Subject:Date; b=Mbnohlt25E8wZkPJcjxq1sTIidYCE9TVJ7TXeoT95TjosOo6ncXgQJIsVbQg1u1x8 aCgqKdI6xgNBFpI+wC7Eot8l5/YGUjs3JUywIYgxKyJJ/BGup0ygj912v2tuqgWo5N sQXlPZDo94j8zAYXd4J20DfBtq0yVEay2nYeN+eE= Received: from H270 (p5b38f6a1.dip0.t-ipconnect.de [91.56.246.161]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 7F787140272 for ; Tue, 4 May 2021 19:22:24 +0000 (UTC) Message-ID: <6C7CD73845304CDE98F6DB165904B571@H270> From: "Stefan Kanthak" To: Subject: [PATCH] vsscanf() in lib/vsprintf.c Date: Tue, 4 May 2021 21:19:47 +0200 Organization: Me, myself & IT MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_2F4E_01D7412B.363FA9A0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6002.18197 X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.24158 X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 4236 X-purgate-ID: 155817::1620156144-0000067D-C9F8850F/0/0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. ------=_NextPart_000_2F4E_01D7412B.363FA9A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi @ll, both and are rather terse and fail to specify the supported arguments and their conversion specifiers/modifiers. tells OTOH: | The behaviour of these functions may vary slightly from those | defined by ANSI, and these deviations are noted in the text. There is but no text (see above) despite multiple deviations from ANSI C | /* '%*[' not yet supported, invalid format */ ... | /* | * Warning: This implementation of the '[' conversion specifier | * deviates from its glibc counterpart in the following ways: ... More deviations (just from reading the source): 1. no support for %p 2. no support for conversion modifiers j and t 3. no support for multibyte characters and strings, i.e. %c and %s may split UTF-8 codepoints 4. accepts %[][c|s], but ignores all conversion modifiers 5. treats %% (and combinations) as %% 6. accepts %n (and combinations) 7. doesn't scan the input for %[...]n 8. uses simple_strto[u]l for the conversion modifier z, i.e. assigns uint32_t to size_t, resulting in truncation Is this intended? If not: patch to fix 5. and 6. and simplify the qualifier handling attached Stefan Kanthak ------=_NextPart_000_2F4E_01D7412B.363FA9A0 Content-Type: application/octet-stream; name="vsprintf.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vsprintf.patch" --- -/lib/vsprintf.c=0A= +++ +/lib/vsprintf.c=0A= @@ -3287,17 +3287,25 @@=0A= str =3D skip_spaces(str);=0A= }=0A= =0A= + if (!*fmt)=0A= + break;=0A= +=0A= /* anything that is not a conversion must match exactly */=0A= - if (*fmt !=3D '%' && *fmt) {=0A= + if (*fmt !=3D '%') {=0A= if (*fmt++ !=3D *str++)=0A= break;=0A= continue;=0A= }=0A= =0A= - if (!*fmt)=0A= - break;=0A= =0A= + /* %% must match % */=0A= + if (*fmt =3D=3D '%') {=0A= + if (*fmt++ !=3D *str++)=0A= + break;=0A= + continue;=0A= + }=0A= +=0A= /* skip this conversion.=0A= * advance both strings to next white space=0A= */=0A= @@ -3315,6 +3323,13 @@=0A= continue;=0A= }=0A= =0A= + if (*fmt =3D=3D 'n') {=0A= + /* return number of characters read so far */=0A= + *va_arg(args, int *) =3D str - buf;=0A= + ++fmt;=0A= + continue;=0A= + }=0A= +=0A= /* get field width */=0A= field_width =3D -1;=0A= if (isdigit(*fmt)) {=0A= @@ -3325,30 +3340,18 @@=0A= =0A= /* get conversion qualifier */=0A= qualifier =3D -1;=0A= - if (*fmt =3D=3D 'h' || _tolower(*fmt) =3D=3D 'l' ||=0A= - *fmt =3D=3D 'z') {=0A= + if (*fmt =3D=3D 'z' || *fmt =3D=3D 'L')=0A= qualifier =3D *fmt++;=0A= + else if (*fmt =3D=3D 'h' || *fmt =3D=3D 'l') {=0A= if (unlikely(qualifier =3D=3D *fmt)) {=0A= - if (qualifier =3D=3D 'h') {=0A= - qualifier =3D 'H';=0A= - fmt++;=0A= - } else if (qualifier =3D=3D 'l') {=0A= - qualifier =3D 'L';=0A= - fmt++;=0A= - }=0A= + qualifier =3D _toupper(qualifier);=0A= + fmt++;=0A= }=0A= }=0A= =0A= if (!*fmt)=0A= break;=0A= =0A= - if (*fmt =3D=3D 'n') {=0A= - /* return number of characters read so far */=0A= - *va_arg(args, int *) =3D str - buf;=0A= - ++fmt;=0A= - continue;=0A= - }=0A= -=0A= if (!*str)=0A= break;=0A= =0A= @@ -3450,11 +3453,6 @@=0A= fallthrough;=0A= case 'u':=0A= break;=0A= - case '%':=0A= - /* looking for '%' in str */=0A= - if (*str++ !=3D '%')=0A= - return num;=0A= - continue;=0A= default:=0A= /* invalid format; stop here */=0A= return num;=0A= ------=_NextPart_000_2F4E_01D7412B.363FA9A0--