From 184a070c5f895d627eedec9757c3e846063b3cd5 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Tue, 8 Sep 2026 13:54:26 -0400
Subject: [PATCH] Remove uses of stpcpy()
This function was only standardized in POSIX.1-2008, is not part of any ISO C standard, and is generally considered unsafe. Use SDL_strlcpy() instead.
---
src/video/wayland/SDL_waylanddatamanager.c | 9 ++++++---
src/video/x11/SDL_x11events.c | 5 ++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index f30719c361612..2a81624e0dcf9 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -589,6 +589,8 @@ static void SelectionOfferNotifyFromMIMEs(SDL_WaylandDataDevice *data_device, bo
// Second pass to fill.
char *strPtr = (char *)(new_mime_types + num_formats + 1);
+ alloc_size -= (uintptr_t)strPtr - (uintptr_t)new_mime_types;
+
item = NULL;
int i = 0;
wl_list_for_each(item, &offer->mimes, link) {
@@ -596,9 +598,10 @@ static void SelectionOfferNotifyFromMIMEs(SDL_WaylandDataDevice *data_device, bo
continue;
}
- new_mime_types[i] = strPtr;
- strPtr = stpcpy(strPtr, item->mime_type) + 1;
- i++;
+ new_mime_types[i++] = strPtr;
+ const size_t len = SDL_strlcpy(strPtr, item->mime_type, alloc_size) + 1;
+ strPtr += len;
+ alloc_size -= len;
}
new_mime_types[num_formats] = NULL;
}
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index b63b2a0eb9365..b28170293fb8d 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -937,11 +937,14 @@ static void X11_HandleClipboardEvent(SDL_VideoDevice *_this, const XEvent *xeven
char **new_mime_types = SDL_AllocateTemporaryMemory(allocationsize);
if (new_mime_types) {
char *strPtr = (char *)(new_mime_types + length + 1);
+ allocationsize -= (uintptr_t)strPtr - (uintptr_t)new_mime_types;
for (j = 0, patom = (Atom *)data; j < length; j++, patom++) {
char *atomStr = X11_XGetAtomName(display, *patom);
new_mime_types[j] = strPtr;
- strPtr = stpcpy(strPtr, atomStr) + 1;
+ const size_t len = SDL_strlcpy(strPtr, atomStr, allocationsize) + 1;
+ strPtr += len;
+ allocationsize -= len;
X11_XFree(atomStr);
}
new_mime_types[length] = NULL;