[Lldb-commits] [lldb] r320242 - Change uses of strncpy in debugserver to strlcpy

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 11 11:29:15 PST 2017

Hi Adrian, 

These are good points, thanks for the feedback.  debugserver is unique in the code base in that it only builds on darwin targets.  Originally it was intended to be a generic standalone gdb-remote protocol stub implementation, but it was only ever implemented for macos and for that matter, we have several Objective-C++ source files in the MacOSX subdir -- I don't think it'll build anywhere but on a mac already.

We have some strncpy's in the main lldb source, I remember going to change some of those to strlcpy's years ago & found that it was not as portable as I'd assumed.

Agreed, using std::string's would be better for most of these.  This was a quick fix to get off of the strncpy's.

Long term I know we're hoping to add our darwin-specific changes to lldb-server and move to that.  But that may not happen for a while.


> On Dec 11, 2017, at 8:26 AM, Adrian McCarthy <amccarth at google.com> wrote:
> I have some concerns about this change.
> 1.  strlcpy is not a C++ standard function, so it's not available for non-POSIX targets.  As far as I can tell, this is the first use of strlcpy in LLVM.
> 2.  In some of the changed calls, the buffer size argument still has a -1, which is redundant with what strlcpy is going to do, so this could cause strings to be truncated a char too soon.
> 3.  At some of the call sites, there remains now-redundant code to guarantee termination.. Since that's the point of changing these calls, we should probably eliminate that.
> 4.  I'm not familiar with this part of the code base.  Is it necessary for the APIs to work with pointer+length rather than a std::string (or other class) that would give us safety and portability?
> On Sun, Dec 10, 2017 at 3:52 PM, Davide Italiano via lldb-commits <lldb-commits at lists.llvm.org> wrote:
> On Fri, Dec 8, 2017 at 7:37 PM, Jason Molenda via lldb-commits
> <lldb-commits at lists.llvm.org> wrote:
> > Author: jmolenda
> > Date: Fri Dec  8 19:37:09 2017
> > New Revision: 320242
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=320242&view=rev
> > Log:
> > Change uses of strncpy in debugserver to strlcpy
> > for better safety.
> >
> > <rdar://problem/32906923>
> >
> Thanks!
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

More information about the lldb-commits mailing list