Add NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH validation

This commit is contained in:
Dmitry Isaenko 2020-05-10 20:30:45 +03:00
parent dd56ef95fe
commit 0848d43bc9

View file

@ -44,6 +44,7 @@ class NxdtUsbAbi1 {
private static final int NXDT_MAX_COMMAND_SIZE = 0x1000;
private static final int NXDT_FILE_CHUNK_SIZE = 0x800000;
private static final int NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH = 0x300;
private static final byte ABI_VERSION = 1;
private static final byte[] MAGIC_NXDT = { 0x4e, 0x58, 0x44, 0x54 };
@ -183,6 +184,12 @@ class NxdtUsbAbi1 {
final int fileNameLen = getLEint(message, 0x18);
String filename = new String(message, 0x20, fileNameLen, StandardCharsets.UTF_8);
if (fileNameLen == 0 || fileNameLen > NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH){
writeUsb(USBSTATUS_MALFORMED_REQUEST);
logPrinter.print("Invalid filename length!", EMsgType.FAIL);
return;
}
logPrinter.print("Write request for: '"+filename+"' ("+fileSize+" bytes)", EMsgType.INFO);
// If RomFs related
if (isRomFs(filename)) {