You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2019/10/25 18:42:39 UTC

[GitHub] [qpid-dispatch] ted-ross commented on a change in pull request #599: DISPATCH-1461: correct the logging of long addresses on attach

ted-ross commented on a change in pull request #599: DISPATCH-1461: correct the logging of long addresses on attach
URL: https://github.com/apache/qpid-dispatch/pull/599#discussion_r339189317
 
 

 ##########
 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:
   Shouldn't you just return size here?  The strlen won't count the closing null if there is one.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org