--- nono/util/runcom/runcom.c 2026/04/29 17:05:16 1.1 +++ nono/util/runcom/runcom.c 2026/04/29 17:05:19 1.1.1.2 @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,9 @@ struct xp_download { // 共有メモリ先頭からのオフセット #define RINGADDR (0x7f00) +// ユーザプログラムの最大サイズ +#define MAX_PROGSIZE (0x7000 - 0x100) + extern int system_datalen; extern unsigned char system_data[]; @@ -114,11 +118,7 @@ make_world(const char *filename) // プログラムをロードして 0100H からにコピー user = load_binary(filename); - len = 0x7000 - 0x100; - if (user.size < len) { - len = user.size; - } - memcpy(rv.data + 0x100, user.data, len); + memcpy(rv.data + 0x100, user.data, user.size); // OS 領域をコピー memcpy(rv.data + 0x7000, system_data, system_datalen); @@ -203,6 +203,10 @@ load_binary(const char *filename) err(1, "lseek(0) failed"); } } + if (dl.size > MAX_PROGSIZE) { + errno = EFBIG; + err(1, "%s", filename); + } dl.data = malloc(dl.size); if (dl.data == NULL) {