You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2008/03/15 16:28:24 UTC
[jira] Created: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
-----------------------------------------------------------------------------------------------------------------------------
Key: STDCXX-765
URL: https://issues.apache.org/jira/browse/STDCXX-765
Project: C++ Standard Library
Issue Type: Bug
Components: Test Driver
Affects Versions: 4.2.0
Environment: All
Reporter: Farid Zaripov
Fix For: 4.2.1
The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
These problems are detected in 0.printf test after lates update.
The schematic patch without error checking is below. This patch is not intended to apply. Its only shows how these bugs should be fixed.
{noformat}
Index: tests/src/fmt_bits.cpp
===================================================================
--- tests/src/fmt_bits.cpp (revision 637399)
+++ tests/src/fmt_bits.cpp (working copy)
@@ -204,9 +204,12 @@
#endif // _RWSTD_NO_EXT_BIN_IO
- len = rw_asnprintf (buf.pbuf, buf.pbufsize,
- "%{+} | %{?}std::ios::%{;}base(%d)",
- spec.fl_pound, base);
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
+ "%{+} | %{?}std::ios::%{;}base(%d)",
+ spec.fl_pound, base);
+ buf.endoff += res;
+ len += res;
}
return len;
@@ -303,9 +306,12 @@
: std::ios::erase_event == event ? "erase_event"
: 0;
- return rw_asnprintf (buf.pbuf, buf.pbufsize,
- "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
- spec.fl_pound, 0 != str, str, event);
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
+ "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
+ spec.fl_pound, 0 != str, str, event);
+ buf.endoff += len;
+ return len;
}
/********************************************************************/
@@ -329,8 +335,12 @@
}
- if (str)
- return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
+ if (str) {
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
+ buf.endoff += len;
+ return len;
+ }
static const Bitnames names [] = {
BITNAME (std::locale, all),
{noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579274#action_12579274 ]
Martin Sebor commented on STDCXX-765:
-------------------------------------
Hmm, [0.printf|http://svn.apache.org/repos/asf/stdcxx/trunk/tests/self/0.printf.cpp] fails 90 assertions on trunk. I tried to find the change to [printf.cpp|http://svn.apache.org/repos/asf/stdcxx/trunk/tests/src/printf.cpp] that's responsible for this but couldn't. Are you saying you know what caused this?
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor updated STDCXX-765:
--------------------------------
Attachment: stdcxx-765.diff
Attached a patch.
ChangeLog:
{noformat}
2008-03-16 Martin Sebor <se...@roguewave.com>
STDCXX-765
* tests/src/fmt_bits.cpp (_rw_bmpfmt): NUL-terminated string so that
it can be appended to using the %{+} directive, taking care not to
make the NUL a part of the formatted string.
(_rw_fmtflags): Same.
(_rw_fmtevent): Same.
(_rw_fmtlc): Same.
{noformat}
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579384#action_12579384 ]
Farid Zaripov commented on STDCXX-765:
--------------------------------------
I have reviewed your patch and patch is ok.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579383#action_12579383 ]
Farid Zaripov commented on STDCXX-765:
--------------------------------------
As for the my patch. It's not a patch, it's just light's the required steps to fix this bug.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579378#action_12579378 ]
Farid Zaripov commented on STDCXX-765:
--------------------------------------
The %{If} and %{Ie} format's along with %{Lc} format weren't exercised in 0.printf until [http://svn.apache.org/viewvc?rev=637399&view=rev this] commit.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (STDCXX-765) Incorrect using
rw_asnprintf() with %{+} format and not NUL-terminated buffer in
_rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579378#action_12579378 ]
farid edited comment on STDCXX-765 at 3/17/08 3:32 AM:
---------------------------------------------------------------
The %{If} and %{Ie} format's along with %{Lc} format weren't exercised in 0.printf until [this|http://svn.apache.org/viewvc?rev=637399&view=rev] commit.
I found this bug when I worked on [22.locale.num.put|http://svn.apache.org/repos/asf/stdcxx/trunk/tests/localization/22.locale.num.put.cpp] test and one of the rw_assertion's with %{If} format directive has failed.
was (Author: farid):
The %{If} and %{Ie} format's along with %{Lc} format weren't exercised in 0.printf until [this|http://svn.apache.org/viewvc?rev=637399&view=rev] commit.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (STDCXX-765) Incorrect using
rw_asnprintf() with %{+} format and not NUL-terminated buffer in
_rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579378#action_12579378 ]
farid edited comment on STDCXX-765 at 3/17/08 3:26 AM:
---------------------------------------------------------------
The %{If} and %{Ie} format's along with %{Lc} format weren't exercised in 0.printf until [this|http://svn.apache.org/viewvc?rev=637399&view=rev] commit.
was (Author: farid):
The %{If} and %{Ie} format's along with %{Lc} format weren't exercised in 0.printf until [http://svn.apache.org/viewvc?rev=637399&view=rev this] commit.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor resolved STDCXX-765.
---------------------------------
Resolution: Fixed
Patch committed in [r638391|http://svn.apache.org/viewvc?rev=638391&view=rev].
Will close after integrating to 4.2.x in the next bulk merge.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579290#action_12579290 ]
Martin Sebor commented on STDCXX-765:
-------------------------------------
Btw., about your proposed patch. I think the approach is correct (my patch does essentially the same thing); the one problem that jumps out at me is that it writes the terminating {{NUL}} directly to the buffer without making sure there's sufficient room.
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12589958#action_12589958 ]
Farid Zaripov commented on STDCXX-765:
--------------------------------------
Merged in 4.2.x branch thus: http://svn.apache.org/viewvc?view=rev&revision=648752
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Martin Sebor
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579288#action_12579288 ]
Martin Sebor commented on STDCXX-765:
-------------------------------------
I stepped through the code and I think I've fixed all the occurrences of the problem -- the [0.printf.cpp|http://svn.apache.org/repos/asf/stdcxx/trunk/tests/self/0.printf.cpp] test passes all assertions with the attached patch applied. Let me know if it looks good to you. I don't think the code in [fmt_bits.cpp|http://svn.apache.org/repos/asf/stdcxx/trunk/tests/src/fmt_bits.cpp] has changed recently so I'm still curious what was masking the bug and what change exposed it...
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Farid Zaripov updated STDCXX-765:
---------------------------------
Description:
The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
These problems are detected in 0.printf test after latest update.
The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
{noformat}
Index: tests/src/fmt_bits.cpp
===================================================================
--- tests/src/fmt_bits.cpp (revision 637399)
+++ tests/src/fmt_bits.cpp (working copy)
@@ -204,9 +204,12 @@
#endif // _RWSTD_NO_EXT_BIN_IO
- len = rw_asnprintf (buf.pbuf, buf.pbufsize,
- "%{+} | %{?}std::ios::%{;}base(%d)",
- spec.fl_pound, base);
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
+ "%{+} | %{?}std::ios::%{;}base(%d)",
+ spec.fl_pound, base);
+ buf.endoff += res;
+ len += res;
}
return len;
@@ -303,9 +306,12 @@
: std::ios::erase_event == event ? "erase_event"
: 0;
- return rw_asnprintf (buf.pbuf, buf.pbufsize,
- "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
- spec.fl_pound, 0 != str, str, event);
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
+ "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
+ spec.fl_pound, 0 != str, str, event);
+ buf.endoff += len;
+ return len;
}
/********************************************************************/
@@ -329,8 +335,12 @@
}
- if (str)
- return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
+ if (str) {
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
+ buf.endoff += len;
+ return len;
+ }
static const Bitnames names [] = {
BITNAME (std::locale, all),
{noformat}
was:
The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
These problems are detected in 0.printf test after lates update.
The schematic patch without error checking is below. This patch is not intended to apply. Its only shows how these bugs should be fixed.
{noformat}
Index: tests/src/fmt_bits.cpp
===================================================================
--- tests/src/fmt_bits.cpp (revision 637399)
+++ tests/src/fmt_bits.cpp (working copy)
@@ -204,9 +204,12 @@
#endif // _RWSTD_NO_EXT_BIN_IO
- len = rw_asnprintf (buf.pbuf, buf.pbufsize,
- "%{+} | %{?}std::ios::%{;}base(%d)",
- spec.fl_pound, base);
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
+ "%{+} | %{?}std::ios::%{;}base(%d)",
+ spec.fl_pound, base);
+ buf.endoff += res;
+ len += res;
}
return len;
@@ -303,9 +306,12 @@
: std::ios::erase_event == event ? "erase_event"
: 0;
- return rw_asnprintf (buf.pbuf, buf.pbufsize,
- "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
- spec.fl_pound, 0 != str, str, event);
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
+ "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
+ spec.fl_pound, 0 != str, str, event);
+ buf.endoff += len;
+ return len;
}
/********************************************************************/
@@ -329,8 +335,12 @@
}
- if (str)
- return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
+ if (str) {
+ (*buf.pbuf) [buf.endoff] = '\0';
+ int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
+ buf.endoff += len;
+ return len;
+ }
static const Bitnames names [] = {
BITNAME (std::locale, all),
{noformat}
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Fix For: 4.2.1
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (STDCXX-765) Incorrect using rw_asnprintf() with
%{+} format and not NUL-terminated buffer in _rw_fmtflags(),
_rw_fmtevent(), _rw_fmtlc()
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-765?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor reassigned STDCXX-765:
-----------------------------------
Assignee: Martin Sebor
> Incorrect using rw_asnprintf() with %{+} format and not NUL-terminated buffer in _rw_fmtflags(), _rw_fmtevent(), _rw_fmtlc()
> -----------------------------------------------------------------------------------------------------------------------------
>
> Key: STDCXX-765
> URL: https://issues.apache.org/jira/browse/STDCXX-765
> Project: C++ Standard Library
> Issue Type: Bug
> Components: Test Driver
> Affects Versions: 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Martin Sebor
> Fix For: 4.2.1
>
> Attachments: stdcxx-765.diff
>
>
> The buf parameter of the _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions contains not NUL-terminated data. The length of data in buf is stored in buf.endoff.
> The rw_asnprintf() function accepts the only buf.pbuf and buf.pbufsize, but not buf.endoff. When %{+} format is used, the length of data in buf calculated using strlen() function, but this length is incorrect due to data is not NUL-terminated.
> Another bug is that _rw_fmtflags(), _rw_fmtevent() and _rw_fmtlc() functions are returns len, but without updating the buf.endoff. Due to this the result of rw_asnprintf() is cutted in further processing.
> These problems are detected in 0.printf test after latest update.
> The schematic patch without error checking is below. This patch is not intended to apply. It's only shows how these bugs should be fixed.
> {noformat}
> Index: tests/src/fmt_bits.cpp
> ===================================================================
> --- tests/src/fmt_bits.cpp (revision 637399)
> +++ tests/src/fmt_bits.cpp (working copy)
> @@ -204,9 +204,12 @@
>
> #endif // _RWSTD_NO_EXT_BIN_IO
>
> - len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+} | %{?}std::ios::%{;}base(%d)",
> - spec.fl_pound, base);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int res = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+} | %{?}std::ios::%{;}base(%d)",
> + spec.fl_pound, base);
> + buf.endoff += res;
> + len += res;
> }
>
> return len;
> @@ -303,9 +306,12 @@
> : std::ios::erase_event == event ? "erase_event"
> : 0;
>
> - return rw_asnprintf (buf.pbuf, buf.pbufsize,
> - "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> - spec.fl_pound, 0 != str, str, event);
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize,
> + "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
> + spec.fl_pound, 0 != str, str, event);
> + buf.endoff += len;
> + return len;
> }
>
> /********************************************************************/
> @@ -329,8 +335,12 @@
>
> }
>
> - if (str)
> - return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + if (str) {
> + (*buf.pbuf) [buf.endoff] = '\0';
> + int len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
> + buf.endoff += len;
> + return len;
> + }
>
> static const Bitnames names [] = {
> BITNAME (std::locale, all),
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.