From: Hollis Blanchard Date: Fri, 9 Feb 2007 20:43:21 +0000 (-0600) Subject: [POWERPC][XEN] strlcpy() fallout. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15327^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c4e6e3c6106518f86e2d0a3062c1bbca152d12ea;p=xen.git [POWERPC][XEN] strlcpy() fallout. - Implement strlcpy() for the dom0 firmware. - Remove strncpy() from dom0 firmware. - Correct buffer length in device tree copying. Signed-off-by: Hollis Blanchard --- diff --git a/xen/arch/powerpc/of-devtree.c b/xen/arch/powerpc/of-devtree.c index 9296a4505a..c437ef4569 100644 --- a/xen/arch/powerpc/of-devtree.c +++ b/xen/arch/powerpc/of-devtree.c @@ -358,7 +358,7 @@ static ofdn_t ofd_node_create( n->on_io = 0; n->on_pathlen = pathlen; n->on_last = ofd_pathsplit_left(path, '/', pathlen); - strlcpy(n->on_path, path, pathlen); + strlcpy(n->on_path, path, pathlen + 1); return pos; } diff --git a/xen/arch/powerpc/of_handler/Makefile b/xen/arch/powerpc/of_handler/Makefile index 4954e374de..3b2dfdbe10 100644 --- a/xen/arch/powerpc/of_handler/Makefile +++ b/xen/arch/powerpc/of_handler/Makefile @@ -27,5 +27,5 @@ obj-y += snprintf.o obj-y += strcmp.o obj-y += strlen.o obj-y += strncmp.o -obj-y += strncpy.o +obj-y += strlcpy.o obj-y += strnlen.o diff --git a/xen/arch/powerpc/of_handler/strlcpy.c b/xen/arch/powerpc/of_handler/strlcpy.c new file mode 100644 index 0000000000..02f33e8d62 --- /dev/null +++ b/xen/arch/powerpc/of_handler/strlcpy.c @@ -0,0 +1,58 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright IBM Corp. 2005, 2007 + * + * Authors: Jimi Xenidis + * Hollis Blanchard + */ + +#include + +size_t +strlcpy(char *dest, const char *src, size_t n) +{ + size_t ret; + char *dp; + + /* cases to consider: + * dest is NULL, s is NULL; + * src is empty (0); + * src is not empty, less than n; + * src is not empty, equal to n; + * src is not empty, greater than n; + */ + + if (n <= 0) { + return 0; + } + + dp = dest; + + do { + *dp++ = *src; + --n; + ++src; + } while ((*src != '\0') && (n > 1)); + + ret = n; + + /* clear remainder of buffer (if any); ANSI semantics */ + while (n > 0) { + *dp++ = '\0'; + --n; + } + return ret; +} diff --git a/xen/arch/powerpc/of_handler/strncpy.c b/xen/arch/powerpc/of_handler/strncpy.c deleted file mode 100644 index 76c5c7182a..0000000000 --- a/xen/arch/powerpc/of_handler/strncpy.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) IBM Corp. 2005 - * - * Authors: Jimi Xenidis - */ - -#include - -char * -strncpy(char *dest, const char *src, size_t n) -{ - char *dp; - - /* cases to consider: - * dest is NULL, s is NULL; - * src is empty (0); - * src is not empty, less than n; - * src is not empty, equal to n; - * src is not empty, greater than n; - */ - - if (n <= 0) { - return dest; - } - - dp = dest; - - do { - *dp++ = *src; - --n; - ++src; - } while ((*src != '\0') && (n > 0)); - - /* clear remainder of buffer (if any); ANSI semantics */ - while (n > 0) { - *dp++ = '\0'; - --n; - } - return dest; -}