fix(libc): reject unsupported format extensions explicitly

This commit is contained in:
SamG-Coder 2026-09-29 06:36:38 +10:00 committed by boykopovar
parent 4e2b200a91
commit a6ea90b919
2 changed files with 12 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#define CORE_LIBS_PRX_LIBC_INCLUDE_WINDOWSSCANNING_HPP
#include "WindowsFormatting.hpp"
#include "General.hpp"
#include <cerrno>
namespace LibcDetail {
@ -25,7 +26,11 @@ inline int ScanWindows(const char* input, const char* format, const void* source
if ((length == "h" && *format == 'h') || (length == "l" && *format == 'l')) length += *format++;
}
const char conversion = *format;
if (!conversion || !std::strchr("diouxXaAeEfFgGcspn[", conversion)) { errno = 22; return EOF; }
if (!conversion) { errno = 22; return EOF; }
if (!std::strchr("diouxXaAeEfFgGcspn[", conversion)) {
NotImplemented_nid_no_patch("vsscanf format conversion");
return EOF;
}
++format;
if (std::strchr("diouxXn", conversion) && (length == "l" || length == "j" || length == "z" || length == "t"))
translated += "ll";

View File

@ -2,6 +2,7 @@
#define CORE_LIBS_PRX_LIBC_INCLUDE_WINDOWSWIDEFORMATTING_HPP
#include "WindowsFormatting.hpp"
#include "General.hpp"
#include <cerrno>
#include <cwchar>
#include <deque>
@ -45,7 +46,11 @@ inline int FormatWideWindows(wchar_t* output, size_t capacity, const wchar_t* fo
if ((length == L"h" && *format == L'h') || (length == L"l" && *format == L'l')) length += *format++;
}
const wchar_t conversion = *format;
if (!conversion || !std::wcschr(L"diouxXaAeEfFgGcspn", conversion)) { errno = 22; return -1; }
if (!conversion) { errno = 22; return -1; }
if (!std::wcschr(L"diouxXaAeEfFgGcspn", conversion)) {
NotImplemented_nid_no_patch("swprintf format conversion");
return -1;
}
++format;
if (std::wcschr(L"diouxXn", conversion) && (length == L"l" || length == L"j" || length == L"z" || length == L"t"))
translated += L"ll";