Hi,
strcpy does not work reliably with overlapping
source and destination buffers. This patch
fixes at least some cases of this problem.
To apply:
cd pmacct-0.11.5
patch -p1 < memmove.patch
Karl <[email protected]>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
diff -ruN pmacct-0.11.5/src/pmacct.c pmacct-0.11.5-memmove/src/pmacct.c
--- pmacct-0.11.5/src/pmacct.c Wed Jul 16 17:38:43 2008
+++ pmacct-0.11.5-memmove/src/pmacct.c Wed Feb 18 17:34:57 2009
@@ -93,16 +93,14 @@
void trim_all_spaces(char *buf)
{
- char *ptr;
int i = 0, len;
- ptr = buf;
len = strlen(buf);
/* trimming all spaces */
while (i <= len) {
- if (isspace(ptr[i])) {
- strcpy(&buf[i], &ptr[i+1]);
+ if (isspace(buf[i])) {
+ memmove(&buf[i], &buf[i+1], len);
len--;
}
else i++;
diff -ruN pmacct-0.11.5/src/util.c pmacct-0.11.5-memmove/src/util.c
--- pmacct-0.11.5/src/util.c Wed Jul 16 17:38:43 2008
+++ pmacct-0.11.5-memmove/src/util.c Wed Feb 18 17:35:40 2009
@@ -169,44 +169,41 @@
void trim_spaces(char *buf)
{
- char *ptr;
int i, len;
- ptr = buf;
len = strlen(buf);
/* trimming spaces at beginning of the string */
for (i = 0; i <= len; i++) {
- if (!isspace(ptr[i])) {
- strcpy(buf, &ptr[i]);
+ if (!isspace(buf[i])) {
+ if (i != 0)
+ memmove(buf, &buf[i], len+1-i);
break;
}
}
- /* trimming spaces at the end of the string */
+ /* trimming spaces at the end of t he string */
for (i = strlen(buf)-1; i >= 0; i--) {
- if (isspace(ptr[i]))
- ptr[i] = '\0';
+ if (isspace(buf[i]))
+ buf[i] = '\0';
else break;
}
}
void trim_all_spaces(char *buf)
{
- char *ptr;
int i = 0, len, quotes = FALSE;
- ptr = buf;
len = strlen(buf);
/* trimming all spaces */
while (i <= len) {
- if (ptr[i] == '\'') {
+ if (buf[i] == '\'') {
if (!quotes) quotes = TRUE;
else if (quotes) quotes = FALSE;
}
- if (isspace(ptr[i]) && !quotes) {
- strcpy(&buf[i], &ptr[i+1]);
+ if (isspace(buf[i]) && !quotes) {
+ memmove(&buf[i], &buf[i+1], len);
len--;
}
else i++;
_______________________________________________
pmacct-discussion mailing list
http://www.pmacct.net/#mailinglists