Skip to content

Commit bfbd2ab

Browse files
committed
fix heap-use-after-free for _HAS_EXCEPTIONS=0
1 parent 5762e6b commit bfbd2ab

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

stl/inc/chrono

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,9 +1725,15 @@ namespace chrono {
17251725

17261726
_EXPORT_STD class _NODISCARD nonexistent_local_time : public runtime_error {
17271727
public:
1728+
#if _HAS_EXCEPTIONS
17281729
template <class _Duration>
17291730
nonexistent_local_time(const local_time<_Duration>& _Tp, const local_info& _Info)
17301731
: runtime_error(_Make_string(_Tp, _Info)) {}
1732+
#else
1733+
template <class _Duration>
1734+
nonexistent_local_time(const local_time<_Duration>&, const local_info&)
1735+
: runtime_error("nonexistent local time") {}
1736+
#endif
17311737

17321738
private:
17331739
template <class _Duration>
@@ -1741,9 +1747,15 @@ namespace chrono {
17411747

17421748
_EXPORT_STD class _NODISCARD ambiguous_local_time : public runtime_error {
17431749
public:
1750+
#if _HAS_EXCEPTIONS
17441751
template <class _Duration>
17451752
ambiguous_local_time(const local_time<_Duration>& _Tp, const local_info& _Info)
17461753
: runtime_error(_Make_string(_Tp, _Info)) {}
1754+
#else
1755+
template <class _Duration>
1756+
ambiguous_local_time(const local_time<_Duration>&, const local_info&)
1757+
: runtime_error("ambiguous local time") {}
1758+
#endif
17471759

17481760
private:
17491761
template <class _Duration>

stl/inc/system_error

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,17 @@ private:
470470
}
471471

472472
protected:
473+
#if _HAS_EXCEPTIONS
473474
_System_error(error_code _Errcode) : runtime_error(_Errcode.message()), _Mycode(_Errcode) {}
474475

475476
_System_error(error_code _Errcode, const string& _Message)
476477
: runtime_error(_Makestr(_Errcode, _Message)), _Mycode(_Errcode) {}
478+
#else
479+
_System_error(error_code _Errcode) : runtime_error("system error"), _Mycode(_Errcode) {}
480+
481+
_System_error(error_code _Errcode, const string&)
482+
: runtime_error("system error"), _Mycode(_Errcode) {}
483+
#endif
477484

478485
error_code _Mycode; // the stored error code
479486
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
RUNALL_INCLUDE ..\usual_20_matrix.lst
5+
RUNALL_CROSSLIST
6+
* PM_CL="/D_HAS_EXCEPTIONS=0"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <cstdio>
5+
#include <chrono>
6+
#include <string>
7+
#include <system_error>
8+
using namespace std;
9+
using namespace chrono;
10+
11+
int main() {
12+
string str{"abc"};
13+
error_code ec{2, system_category()};
14+
system_error syserr{ec};
15+
16+
ambiguous_local_time alt{local_time<seconds>{}, local_info{}};
17+
18+
nonexistent_local_time nlt{local_time<seconds>{}, local_info{}};
19+
20+
printf("%s\n%s\n%s\n", syserr.what(), alt.what(), nlt.what());
21+
}
22+

0 commit comments

Comments
 (0)