mirror of https://github.com/maderix/ANE.git
fix(HIGH-02): add realpath() validation for data and model paths
- train_large.m: realpath() guard for DATA_PATH before open() provides clear error message when run from wrong directory - train_large.m: realpath() audit log in load_pretrained() for model path ref: docs/reports/security-audit-2026-03-02.md HIGH-02
This commit is contained in:
parent
ef1bb7dec1
commit
8929afc887
|
|
@ -4,6 +4,7 @@
|
||||||
#include "stories_io.h"
|
#include "stories_io.h"
|
||||||
#include "stories_mil.h"
|
#include "stories_mil.h"
|
||||||
#include "stories_cpu_ops.h"
|
#include "stories_cpu_ops.h"
|
||||||
|
#include <limits.h> // PATH_MAX for realpath() (HIGH-02)
|
||||||
|
|
||||||
#define CKPT_PATH "ane_stories110M_ckpt.bin"
|
#define CKPT_PATH "ane_stories110M_ckpt.bin"
|
||||||
#define MODEL_PATH "../../assets/models/stories110M.bin"
|
#define MODEL_PATH "../../assets/models/stories110M.bin"
|
||||||
|
|
@ -13,6 +14,7 @@
|
||||||
static bool load_pretrained(LayerWeights *lw, float *rms_final, float *embed, const char *path) {
|
static bool load_pretrained(LayerWeights *lw, float *rms_final, float *embed, const char *path) {
|
||||||
FILE *f = fopen(path, "rb");
|
FILE *f = fopen(path, "rb");
|
||||||
if (!f) { printf("Cannot open %s\n", path); return false; }
|
if (!f) { printf("Cannot open %s\n", path); return false; }
|
||||||
|
{ char rp[PATH_MAX]; if (realpath(path, rp)) printf(" Model path: %s\n", rp); } // HIGH-02: audit resolved path
|
||||||
Llama2Config cfg;
|
Llama2Config cfg;
|
||||||
// Validate config read — gatekeeper before any dimension-based logic (CRIT-03)
|
// Validate config read — gatekeeper before any dimension-based logic (CRIT-03)
|
||||||
if (fread(&cfg, sizeof(cfg), 1, f) != 1) {
|
if (fread(&cfg, sizeof(cfg), 1, f) != 1) {
|
||||||
|
|
@ -289,6 +291,15 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mmap token data
|
// mmap token data
|
||||||
|
// HIGH-02: validate DATA_PATH resolves before open() to give a clear error when CWD is wrong
|
||||||
|
{
|
||||||
|
char rp[PATH_MAX];
|
||||||
|
if (!realpath(DATA_PATH, rp)) {
|
||||||
|
fprintf(stderr, "Data file not found: '%s'\n"
|
||||||
|
" Hint: run train_large from the training/ directory.\n", DATA_PATH);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
int data_fd = open(DATA_PATH, O_RDONLY);
|
int data_fd = open(DATA_PATH, O_RDONLY);
|
||||||
if (data_fd < 0) { printf("Cannot open %s\n", DATA_PATH); return 1; }
|
if (data_fd < 0) { printf("Cannot open %s\n", DATA_PATH); return 1; }
|
||||||
struct stat st; fstat(data_fd, &st);
|
struct stat st; fstat(data_fd, &st);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue