Skip to content

Maybe a problem with some vsnprintf implementations? #655

@geoffmcl

Description

@geoffmcl

In all my linux installations the option --mute-id yes does not give the correct message output. This was in Ubuntu 14.04 64-bit, 16.04 32-bit, and Raspbian 32-bit...

It works fine in Windows 10 64-bit, and XP 32-bit...

The problem appears to be the use of the output buffer as one of the inputs in the va_list... the stackoverflow post does indicate this may not be safe in all implementations... and found other similar indications...

If have prepared a small test_vsnprintf test app which should demonstrate the problem, if there is one...

Since I initially thought this might be a regression test problem for case 629, I filed a report there, Issue 26, and that included a patch, now repeated here, which fixed it for me -

diff --git a/src/messageobj.c b/src/messageobj.c
index 6f76152..7b9b415 100644
--- a/src/messageobj.c
+++ b/src/messageobj.c
@@ -158,8 +158,14 @@ static TidyMessageImpl *tidyMessageCreateInitV( TidyDocImpl *doc,
 
     if ( ( cfgBool(doc, TidyMuteShow) == yes ) && level <= TidyFatal )
     {
-        TY_(tmbsnprintf)(result->messageOutputDefault, sizeMessageBuf, "%s (%s)", result->messageOutputDefault, TY_(tidyErrorCodeAsKey)(code) );
-        TY_(tmbsnprintf)(result->messageOutput, sizeMessageBuf, "%s (%s)", result->messageOutput, TY_(tidyErrorCodeAsKey)(code) );
+        ctmbstr pc = TY_(tidyErrorCodeAsKey)(code);
+        i = TY_(tmbstrlen)(result->messageOutputDefault);
+        if (i < sizeMessageBuf)
+            TY_(tmbsnprintf)(result->messageOutputDefault+i, sizeMessageBuf-i, " (%s)", pc );
+        i = TY_(tmbstrlen)(result->messageOutput);
+        if (i < sizeMessageBuf)
+            TY_(tmbsnprintf)(result->messageOutput+i, sizeMessageBuf-i, " (%s)", pc );
+        i = 0;
     }
 
     result->allowMessage = yes;

Since this option was implemented by @balthisar, who also added case 629 at the same time, I have been waiting for his comments, but seems he is busy with RL at the moment...

It is not paticularly urgent, since as far as I can see it only effects the new option --muted-id yes, but would be appreciated if meantime others could test, apply the patch, and report... thanks...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions