Skip to content

Commit 93e4446

Browse files
LibretroAdminLibretroAdmin
authored andcommitted
Fix buffer overflow vulnerabilities in PS2 platform driver
Replace unsafe sprintf() calls with safe strlcpy using return value offsets for concatenation. This prevents buffer overflows while maintaining the same string construction logic. CRITICAL SECURITY ISSUE: - mountPoint buffer is only 10 bytes but sprintf() has no bounds checking - partition buffer is only 50 bytes but sprintf() has no bounds checking - Risk: Remote code execution via path string buffer overflow Changes: - sprintf(partition, "%s:%s", ...) -> strlcpy with offset concatenation - sprintf(mountPoint, "%s:", ...) -> strlcpy with offset concatenation - sprintf(newCWD, "%s%s", ...) -> strlcpy with offset concatenation Uses strlcpy return values as offsets for safe string building.
1 parent 8170665 commit 93e4446

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

frontend/drivers/platform_ps2.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,25 @@ bool getMountInfo(char *path, char *mountPoint, char *partition, char *newCWD)
148148
return false;
149149
}
150150

151-
sprintf(partition, "%s:%s",
152-
str_list->elems[0].data, str_list->elems[1].data);
153-
sprintf(mountPoint, "%s:",
154-
str_list->elems[2].data);
155-
sprintf(newCWD, "%s%s",
156-
mountPoint,
157-
str_list->size >= 4 ? str_list->elems[3].data : "");
151+
/* Build partition string: "device:path" using strlcpy offsets */
152+
size_t len = strlcpy(partition, str_list->elems[0].data, 50);
153+
if (len < 50) {
154+
len += strlcpy(partition + len, ":", 50 - len);
155+
if (len < 50)
156+
strlcpy(partition + len, str_list->elems[1].data, 50 - len);
157+
}
158+
159+
/* Build mountPoint string: "mount:" using strlcpy offset */
160+
len = strlcpy(mountPoint, str_list->elems[2].data, 10);
161+
if (len < 10)
162+
strlcpy(mountPoint + len, ":", 10 - len);
163+
164+
/* Build newCWD string using strlcpy offset */
165+
len = strlcpy(newCWD, mountPoint, FILENAME_MAX);
166+
if (len < FILENAME_MAX)
167+
strlcpy(newCWD + len,
168+
str_list->size >= 4 ? str_list->elems[3].data : "",
169+
FILENAME_MAX - len);
158170

159171
string_list_free(str_list);
160172
return true;

0 commit comments

Comments
 (0)