[ 
https://issues.apache.org/jira/browse/DISPATCH-1461?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16959987#comment-16959987
 ] 

ASF GitHub Bot commented on DISPATCH-1461:
------------------------------------------

kgiusti commented on pull request #599: DISPATCH-1461: correct the logging of 
long addresses on attach
URL: https://github.com/apache/qpid-dispatch/pull/599#discussion_r339192856
 
 

 ##########
 File path: src/router_core/terminus.c
 ##########
 @@ -76,30 +76,49 @@ void qdr_terminus_free(qdr_terminus_t *term)
 }
 
 
+// DISPATCH-1461: snprintf() is evil - it returns >= size on overflow.  This
+// wrapper will never return >= size, even if truncated.  This makes it safe to
+// do pointer & length arithmetic without overflowing the destination buffer in
+// qdr_terminus_format()
+//
+static inline int safe_snprintf(char *str, size_t size, const char *format, 
...)
+{
+    va_list ap;
+    va_start(ap, format);
+    int rc = vsnprintf(str, size, format, ap);
+    va_end(ap);
+
+    if (size && rc >= size)
+        return strlen(str);  // return actual # of bytes written
 
 Review comment:
   Ok, patch updated.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Crashed router due to terminus address overflow
> -----------------------------------------------
>
>                 Key: DISPATCH-1461
>                 URL: https://issues.apache.org/jira/browse/DISPATCH-1461
>             Project: Qpid Dispatch
>          Issue Type: Bug
>          Components: Router Node
>    Affects Versions: 1.9.0
>            Reporter: Ken Giusti
>            Priority: Blocker
>             Fix For: 1.10.0
>
>
> in router_core/connections.c::qdr_link_inbound_first_attach_CT:
>  
> {quote}{{char source_str[1000];}}
> {{ char target_str[1000];}}
> {{ size_t source_len = 1000;}}
> {{ size_t target_len = 1000;}}{{source_str[0] = '\0';}}
> {{ target_str[0] = '\0';}}{{//}}
> {{ // Grab the formatted terminus strings before we schedule any IO-thread 
> processing that}}
> {{ // might get ahead of us and free the terminus objects before we issue the 
> log.}}
> {{ //}}
> {{ if (qd_log_enabled(core->log, QD_LOG_INFO)) {}}
> {{     qdr_terminus_format(source, source_str, &source_len);}}
> {{     qdr_terminus_format(target, target_str, &target_len);}}
> {{ }}}{quote}
> {{If the source or target terminus is too long (>1000) the output string 
> overflows.}}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to