This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Avoid overlapping addresses to stpcpy calls in nscd (BZ #16760)
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: libc-alpha at sourceware dot org, Siddhesh Poyarekar <siddhesh at redhat dot com>
- Date: Thu, 27 Mar 2014 20:22:54 +0100
- Subject: Re: [PATCH] Avoid overlapping addresses to stpcpy calls in nscd (BZ #16760)
- Authentication-results: sourceware.org; auth=none
- References: <20140327040406 dot GA26264 at spoyarek dot pnq dot redhat dot com> <1499542 dot yzGAIksTkn at vapier>
On Thu, Mar 27, 2014 at 03:34:11AM -0400, Mike Frysinger wrote:
> On Thu 27 Mar 2014 09:34:06 Siddhesh Poyarekar wrote:
> > Calls to stpcpy from nscd netgroups code will have overlapping source
> > and destination when all three values in the returned triplet are
> > non-NULL and in the expected (host,user,domain) order. This is seen
> > in valgrind as:
> >
> > Fix this by using memmove instead of stpcpy. Tested x86_64 using
> > various combinations of triplets (including NULL and non-NULL ones) to
> > verify that this works correctly and there are no regressions.
>
This could work only with additional assertion that we do not move host
forward otherwise it could overwrite user.
> i feel like we've wanted an equivalent of stpcpy/memccpy for memmove. good
> time to add it ? :)
>
Yes, it would be better to use this at least internally, perhaps this
patch instead is cleaner.
Other possibility is keep these in separate header like second snippet,
do you have better name for that? Also I could make a stpcat and move
equivalent, not sure with what name.
Her I would fix a root cause of these bugs which is bad design. We mix
temporary buffer with building result. If we use separate buffers for
that a code would be lot simpler, I will prepare patch for it.
diff --git a/string/extension.h b/string/extension.h
new file mode 100644
index 0000000..963dccf
--- /dev/null
+++ b/string/extension.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 2014 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+
+#ifndef _STRING_EXTENSION_H
+#define _STRING_EXTENSION_H 1
+
+#include <stdint.h>
+#include <string.h>
+
+
+static inline
+char *
+stpmove (char *dest, const char *src)
+{
+ size_t len = strlen (src);
+ memmove (dest, src, len);
+ return dest + len;
+}
+
+
+#endif