T09 · Insecure Skill Coding Practices
- Location
memory.c:986- Finding
Unvalidated Shard Names Permit Filesystem Path Escape
- Content
View full analysis
shard_count >= MAX_SHARDS) { fprintf(stderr,"max shards (%d) reached\n",MAX_SHARDS); return NULL; } int idx = ctx->shard_count; strncpy(ctx->shards[idx].name, name, 63); ctx->shards[idx].name[63] = '\0'; /* 子数据目录: data_dir/shard_/ */ char sd[1024]; snprintf(sd, sizeof(sd), "%s/shard_%s", ctx->data_dir, name); MemoryCtx *sc = (MemoryCtx*)calloc(1, sizeof(MemoryCtx)); if (!sc) return NULL; ctx->shards[idx].ctx = sc; ctx->shard_count++; /* 小池: 256KB 每个 shard */ sc->wal_disabled = 1; if (pool_init(&sc->pool, SHARD_POOL_SIZE) < 0) { free(sc); ctx->shard_count--; return NULL; } hash_init(&sc->table); tag_init(&sc->tag_index); sl_init(&sc->sorted); strncpy(sc->data_dir, sd, sizeof(sc->data_dir)-1); sc->file_ttl = ctx->file_ttl; sc->initialized = 1; /* 加载 shard 的持久化数据 */ ovf_load(sc); ovf_clean(sc); char wf[1024]; wal_path(wf, sizeof(wf), sd); int restored = wal_replay(sc, wf); wal_compact(wf); ``` ### Technical Analysis The shard name is accepted directly from the `--shard` argument or the `shard create` command and interpolated into a filesystem path. There is no validation preventing path separators, traversal components, or names that resolve through attacker-controlled symbolic links. The resulting path is assigned to `sc->data_dir` and used by the WAL, snapshot, loading, cleanup, and eviction subsystems. In particular, `wal_compact()` opens the generated `wal.log` path in truncating mode. Later operatio ...[truncated 2063 chars]- Remediation
View remediation
