public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r14-2638] libstdc++: Check for multiple modifiers in chrono format string [PR110708]
Date: Wed, 19 Jul 2023 10:11:50 +0000 (GMT)	[thread overview]
Message-ID: <20230719101150.462C43858C66@sourceware.org> (raw)

https://gcc.gnu.org/g:52bfec7ea0eb0f1a4c5bfa55b0d6b9b6c8808e26

commit r14-2638-g52bfec7ea0eb0f1a4c5bfa55b0d6b9b6c8808e26
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jul 18 10:36:37 2023 +0100

    libstdc++: Check for multiple modifiers in chrono format string [PR110708]
    
    The logic for handling modified chrono specs like %Ey was just
    restarting the loop after each modifier, and not checking whether we'd
    already seen a modifier.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/110708
            * include/bits/chrono_io.h (__formatter_chrono::_M_parse): Only
            allow a single modifier.
            * testsuite/std/time/format.cc: Check multiple modifiers.

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h     |  5 +++++
 libstdc++-v3/testsuite/std/time/format.cc | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h
index 87caa30b83a..5f06a6d76b4 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -426,6 +426,11 @@ namespace __format
 		  break;
 		case 'O':
 		case 'E':
+		  if (__mod) [[unlikely]]
+		    {
+		      __allowed_mods = _Mod_none;
+		      break;
+		    }
 		  __mod = __c;
 		  continue;
 		default:
diff --git a/libstdc++-v3/testsuite/std/time/format.cc b/libstdc++-v3/testsuite/std/time/format.cc
index b05e5da1af8..0dc45d58dce 100644
--- a/libstdc++-v3/testsuite/std/time/format.cc
+++ b/libstdc++-v3/testsuite/std/time/format.cc
@@ -68,6 +68,16 @@ test_bad_format_strings()
   // modifier not valid for conversion specifier
   VERIFY( not is_format_string_for("{:%Ea}", t) );
   VERIFY( not is_format_string_for("{:%Oa}", t) );
+
+  // more than one modifier (PR libstdc++/110708)
+  VERIFY( not is_format_string_for("{:%EEc}", t) );
+  VERIFY( not is_format_string_for("{:%EEEc}", t) );
+  VERIFY( not is_format_string_for("{:%OOd}", t) );
+  VERIFY( not is_format_string_for("{:%OOOd}", t) );
+  VERIFY( not is_format_string_for("{:%EEy}", t) );
+  VERIFY( not is_format_string_for("{:%OOy}", t) );
+  VERIFY( not is_format_string_for("{:%OEy}", t) );
+  VERIFY( not is_format_string_for("{:%EOy}", t) );
 }
 
 template<typename I>

                 reply	other threads:[~2023-07-19 10:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230719101150.462C43858C66@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).