E-01修复:poll超长守卫前置st.size根治死码,save输出上限收紧4096,写盘闸拦截与自检留痕
This commit is contained in:
@@ -302,6 +302,65 @@ static int run_cfgtest(void)
|
||||
}
|
||||
}
|
||||
printf("[cfgtest] OK surgical save (comment kept, value intact)\n");
|
||||
|
||||
/* E-01 场景 1:伪造超长文件(> CFG_FILE_MAX_LEN)→ poll 必须判损坏
|
||||
* (与 load/MCU 同一契约):RAM 回工厂默认 + 文件重建为出厂模板,
|
||||
* 而非截断解析残留 10.0.0.1(修复前死码走的是截断分支) */
|
||||
{
|
||||
uint8_t big[CFG_FILE_MAX_LEN + 64u];
|
||||
cfg_file_stat_t st_chk;
|
||||
|
||||
(void)memset(big, ';', sizeof(big)); /* 纯注释:内容无关,尺寸超即触发 */
|
||||
if (cfg_store_write_atomic(cfg_store_config_path(), big, sizeof(big)) != 0) {
|
||||
printf("[cfgtest] FAIL forge oversized write\n");
|
||||
return 1;
|
||||
}
|
||||
cfg_file_poll(); /* 检出变更(沉降计数 1) */
|
||||
cfg_file_poll(); /* 沉降完成 → 损坏分支:工厂默认 + 重建模板 */
|
||||
|
||||
if (cfg_store_stat(cfg_store_config_path(), &st_chk) != 0 ||
|
||||
st_chk.size == 0u || st_chk.size > CFG_FILE_MAX_LEN) {
|
||||
printf("[cfgtest] FAIL oversized file not rebuilt (size=%lu)\n",
|
||||
(unsigned long)st_chk.size);
|
||||
return 1;
|
||||
}
|
||||
p_cfg = net_cfg_get();
|
||||
if (p_cfg->ip[0] != 192u || p_cfg->ip[1] != 168u ||
|
||||
p_cfg->ip[2] != 1u || p_cfg->ip[3] != 100u) {
|
||||
printf("[cfgtest] FAIL ip not factory after oversized: %u.%u.%u.%u\n",
|
||||
(unsigned)p_cfg->ip[0], (unsigned)p_cfg->ip[1],
|
||||
(unsigned)p_cfg->ip[2], (unsigned)p_cfg->ip[3]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("[cfgtest] OK oversized file rebuilt to factory template\n");
|
||||
|
||||
/* E-01 场景 2:save 拒写"雷"文件——伪造合法界内纯注释文件(4000B,无
|
||||
* [network] 段),外科手术保存文末补写受管段 → 输出必然超
|
||||
* CFG_FILE_MAX_LEN:必须拒绝(net_cfg_save 返 -1)且原文件不动;
|
||||
* 修复前此处会成功写出 ~4200B 超长文件 = 下次开机被销毁的雷 */
|
||||
{
|
||||
uint8_t pad[4000u];
|
||||
cfg_file_stat_t st_chk;
|
||||
|
||||
(void)memset(pad, ';', sizeof(pad));
|
||||
if (cfg_store_write_atomic(cfg_store_config_path(), pad, sizeof(pad)) != 0) {
|
||||
printf("[cfgtest] FAIL forge padding write\n");
|
||||
return 1;
|
||||
}
|
||||
if (net_cfg_save() == 0) {
|
||||
printf("[cfgtest] FAIL oversized document was written (landmine)\n");
|
||||
return 1;
|
||||
}
|
||||
(void)cfg_store_stat(cfg_store_config_path(), &st_chk);
|
||||
if (st_chk.size != 4000u) {
|
||||
printf("[cfgtest] FAIL file modified by rejected save (size=%lu)\n",
|
||||
(unsigned long)st_chk.size);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("[cfgtest] OK save rejected oversized document (file untouched)\n");
|
||||
|
||||
printf("[cfgtest] PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user