[lxc-devel] [PATCH 2/6] Delete string from array Add function to delete a string from a non-null terminated buffer
Serge Hallyn
serge.hallyn at ubuntu.com
Mon Sep 7 19:21:00 UTC 2015
Quoting Christian Brauner (christianvanbrauner at gmail.com):
> On Mon, Sep 07, 2015 at 05:03:37PM +0000, Serge Hallyn wrote:
> > Quoting Serge Hallyn (serge.hallyn at ubuntu.com):
> > > Quoting Christian Brauner (christianvanbrauner at gmail.com):
> > >
> > > I'm probably wrong, but
> > >
> > > 1. if the buffer is non-null-terminated, then can't the memmove of
> > > strlen(del) - needlelen + 1 end up in a segv?
> > > 2. the comment should probably mention newlines. If needle doesn't
> > > include newline, and the string is a policy, we'll end up
> > > with extra newlines. Which may not matter, unless we do
> > > thousands of operations on a container...
> >
> > In fact, if it is not null-terminated, you can't do the strlen(del)
> > safely, can you?
>
> Right, I would change
> memmove(del, del + needlelen, strlen(del) - needlelen + 1);
> to
> memmove(del, del + needlelen, strnlen(del, haystacklen) - needlelen);
Should probably be somethin glike
memmove(del, del + needlelen, strnlen(del, haystacklen-del) - needlelen);
del[needlelen] = '\0';
I'm not convinced eventhat is right. We may need to either always assume it is
null-terminated, or always track the current valid length of the string. (and/or
keep extra state showing whether null-terminated or not)
> The Current master relies on the same idea in mod_rdep(), I'll send a patch for
> the current master in a few minutes, unless you're on it right now.
I'm not. Thanks.
More information about the lxc-devel
mailing list