From: Nadav Har'El <n...@scylladb.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

libc: fix build of __strcpy_chk

Our implementation of __strcpy_chk called our implementation of __stpcpy_chk
as both of these do the same thing and just return a different return
value.

However, gcc 12.1.1 got confused thinking that this call was recursive -
perhaps because they map both of them to the same internal function (I
don't understand how, because they return different values...).

In any case, the implementation of __strcpy_chk is fairly trivial, so
we can just open-code it instead of calling __stpcpy_chk.

This is one of the fixes needed to build on Fedora 36 (refs #1198).

Signed-off-by: Nadav Har'El <n...@scylladb.com>

---
diff --git a/libc/string/__strcpy_chk.c b/libc/string/__strcpy_chk.c
--- a/libc/string/__strcpy_chk.c
+++ b/libc/string/__strcpy_chk.c
@@ -1,9 +1,10 @@
 #include <string.h>
+#include <assert.h>
 
 /* Used by code compiled on Linux with -D_FORTIFY_SOURCE */
-extern char *__stpcpy_chk (char *dest, const char *src, size_t destlen);
 char *__strcpy_chk (char *dest, const char *src, size_t destlen)
 {
-    __stpcpy_chk (dest, src, destlen);
-    return dest;
+    // TODO: This repeats some of strcpy's work. Make it more efficent.
+    assert(strlen(src) < destlen);
+    return strcpy(dest, src);
 }

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000dbb14505e24c4f62%40google.com.

Reply via email to