updated: [96fc77b] fixed canonicalize_pathname() breakage: fixed str_move() function (memmove semantics) again
Sergei Trofimovich
slyfox at inbox.ru
Tue Feb 10 11:49:58 UTC 2009
The following commit has been merged in the master branch:
commit 96fc77bc3ee1f2ae2ae7c0a14d3bf08975b4cb66
Author: Sergei Trofimovich <slyfox at inbox.ru>
Date: Sat Feb 7 16:10:33 2009 +0200
fixed canonicalize_pathname() breakage: fixed str_move() function (memmove semantics) again
This patch reintroduces fix firstly appeared in (and recently broken by mhl revert)
> commit e48cb7c89ff3e54de70130a3de2136a9902a023d
> Author: Sergei Trofimovich <st at anti-virus.by>
> Date: Fri Jan 30 09:31:28 2009 +0200
>
> mhl: added mhl_strmove() function (memmove semantics)
...
> Snippet of man strcpy:
> DESCRIPTION
> The strcpy() function copies the string pointed to by src, including the terminating
> null byte ('\0'), to the buffer pointed to by dest. ___The strings may not overlap___,
> and the destination string dest must be large enough to receive the copy.
> We used strcpy to move data chunk in memory: "./foo" -> "foo", etc.
>
> This patch introduces mhl_strmove and fixed canonicalize_pathname.
Signed-off-by: Sergei Trofimovich <slyfox at inbox.ru>
diff --git a/src/util.h b/src/util.h
index 1ac88dd..e108424 100644
--- a/src/util.h
+++ b/src/util.h
@@ -2,7 +2,8 @@
#define MC_UTIL_H
#include <sys/types.h>
-
+#include <assert.h>
+#include <string.h>
/* Returns its argument as a "modifiable" string. This function is
* intended to pass strings to legacy libraries that don't know yet
@@ -263,7 +264,28 @@ char *shell_unescape( const char * );
char *shell_escape( const char * );
#define str_dup_range(s_start, s_bound) (g_strndup(s_start, s_bound - s_start))
-#define str_move(dest, src) (g_strlcpy(dest,src,strlen(src)))
+
+/*
+ * strcpy is unsafe on overlapping memory areas, so define memmove-alike
+ * string function.
+ * Have sense only when:
+ * * dest <= src
+ * AND
+ * * dest and str are pointers to one object (as Roland Illig pointed).
+ *
+ * We can't use str*cpy funs here:
+ * http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294
+ */
+static inline char * str_move(char * dest, const char * src)
+{
+ size_t n;
+
+ assert (dest<=src);
+
+ n = strlen (src) + 1; /* + '\0' */
+
+ return memmove (dest, src, n);
+}
#define MC_PTR_FREE(ptr) do { g_free(ptr); (ptr) = NULL; } while (0)
--
Midnight Commander Development
More information about the mc-devel
mailing list