From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11706 Path: news.gmane.org!.POSTED!not-for-mail From: Bartosz Brachaczek Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] handle whitespace before %% in scanf Date: Sun, 9 Jul 2017 23:00:18 +0200 Message-ID: <20170709210018.16369-1-b.brachaczek@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1499634055 6703 195.159.176.226 (9 Jul 2017 21:00:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 9 Jul 2017 21:00:55 +0000 (UTC) Cc: Bartosz Brachaczek To: musl@lists.openwall.com Original-X-From: musl-return-11719-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jul 09 23:00:51 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dUJJu-0001Jl-AJ for gllmg-musl@m.gmane.org; Sun, 09 Jul 2017 23:00:46 +0200 Original-Received: (qmail 30703 invoked by uid 550); 9 Jul 2017 21:00:49 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30674 invoked from network); 9 Jul 2017 21:00:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rTAJYNTb7rvB9eRsvJZCSSg1An9u+ZwAi9dDVyZ7lHc=; b=WWnOhUKENAEHnka9fZrWIKtMIFWXiaymSF7CKItL/OraPDs9wygVE6KrGlhyBFFGsg xrlmQSHDWzxah5ThmSbhShdUCbix0s47nlU3gW37FUrZiiFZHkgERkNL9xsByT6w3S8+ vwkaDSukHyvvF6XYQzBf8Nk9ciFe3I+t/JZJFdzsC/4trIgALC6ZbQZ/3lTVX8JIie6Y ThBGeFZAj1NqkN0ssDDnPoL4PzeO88b6L2+tff+3bjDUWCdkfBNAZprxyHcZcOfk5XZv xJ38iDPy3E1UUjckG1NLIifJRlP4EVQpPgAIJYNSFXuGoPGhqe7s1y0ry8uldIMn69cQ 0KHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rTAJYNTb7rvB9eRsvJZCSSg1An9u+ZwAi9dDVyZ7lHc=; b=pfUc5UocL52bFSA1XrzWTDH8e+LGRqb6PXuqgyECbHBX0Yte4rqw/g1mW2cUe39rsZ nZSDAXNAKhmWagVO4G/svlc/wMcgkmisVz3ZNA6TJg0FXkSTNgQJL/uKaaw4eralUw4J vep/2BLsiWWboZ5WXHmFeQ0X98/EXRmRu2Osba342dpw5Ug0VqJL8LrVtejh6tWIOckO n+m9R9j2DWKxuAk3QZRR4PiBeGVNir5tYcR0kqsH+cDMEiDOftcaMDVOKAKbywDn7c8u aPJCY/quWMGQ+/F+21zwhCTdf6a2Pnknp+Y2wjl+j8kp3lJvCE6aaTjldPWCUay7p+Jo lXkQ== X-Gm-Message-State: AIVw1106UDQOyMK6IiuL3/be1JYVR4BFEiDARTsuivtEUncFiKXiGjw1 bHPdwkv6LiuyAT/K070= X-Received: by 10.223.145.227 with SMTP id 90mr5221974wri.171.1499634036925; Sun, 09 Jul 2017 14:00:36 -0700 (PDT) X-Mailer: git-send-email 2.13.0 Xref: news.gmane.org gmane.linux.lib.musl.general:11706 Archived-At: this is mandated by C and POSIX standards and is in accordance with glibc behavior. --- src/stdio/vfscanf.c | 10 +++++++--- src/stdio/vfwscanf.c | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index d4d2454b..9e030fc4 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -89,15 +89,19 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) continue; } if (*p != '%' || p[1] == '%') { - p += *p=='%'; shlim(f, 0); - c = shgetc(f); + if (*p == '%') { + p++; + while (isspace((c=shgetc(f)))); + } else { + c = shgetc(f); + } if (c!=*p) { shunget(f); if (c<0) goto input_fail; goto match_fail; } - pos++; + pos += shcnt(f); continue; } diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index ad8e2b9a..5d387a2d 100644 --- a/src/stdio/vfwscanf.c +++ b/src/stdio/vfwscanf.c @@ -117,8 +117,12 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) continue; } if (*p != '%' || p[1] == '%') { - p += *p=='%'; - c = getwc(f); + if (*p == '%') { + p++; + while (iswspace((c=getwc(f)))) pos++; + } else { + c = getwc(f); + } if (c!=*p) { ungetwc(c, f); if (c<0) goto input_fail; -- 2.13.0