diff --git a/stub/cbits/stub.cpp b/stub/cbits/stub.cpp
index 1decbd7f31105b48d33c89fe68e545cbb35b0253..649e9d9d85ccc6f915d4e7b6d32e0c31302a4148 100644
--- a/stub/cbits/stub.cpp
+++ b/stub/cbits/stub.cpp
@@ -509,7 +509,7 @@ void serve(void) {
         local.sun_family = AF_UNIX;
         const char* sock = getenv("GHC_DEBUG_SOCKET");
         if (sock == NULL){ sock = "/tmp/ghc-debug"; }
-        strcpy(local.sun_path, sock);
+        strncpy(local.sun_path, sock, sizeof(local.sun_path));
         unlink(local.sun_path);
         if (bind(s, (struct sockaddr *) &local, sizeof(local)) != 0) {
             barf("bind failed");