Limit file.open() names to 31 char max C string format. See #1112

This commit is contained in:
TerryE 2016-03-04 01:46:35 +00:00
parent 5684392911
commit 1e49d03dbc
3 changed files with 6 additions and 5 deletions

View File

@ -20,7 +20,7 @@ static int file_open( lua_State* L )
} }
const char *fname = luaL_checklstring( L, 1, &len ); const char *fname = luaL_checklstring( L, 1, &len );
luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long"); luaL_argcheck(L, len < FS_NAME_MAX_LENGTH && c_strlen(fname) == len, 1, "filename invalid");
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");

View File

@ -764,7 +764,8 @@ static s32_t spiffs_read_dir_v(
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) { (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
struct spiffs_dirent *e = (struct spiffs_dirent *)user_p; struct spiffs_dirent *e = (struct spiffs_dirent *)user_p;
e->obj_id = obj_id; e->obj_id = obj_id;
strcpy((char *)e->name, (char *)objix_hdr.name); strncpy((char *)e->name, (char *)objix_hdr.name, SPIFFS_OBJ_NAME_LEN);
e->type = objix_hdr.type; e->type = objix_hdr.type;
e->size = objix_hdr.size == SPIFFS_UNDEFINED_LEN ? 0 : objix_hdr.size; e->size = objix_hdr.size == SPIFFS_UNDEFINED_LEN ? 0 : objix_hdr.size;
e->pix = pix; e->pix = pix;

View File

@ -1349,7 +1349,7 @@ static s32_t spiffs_object_find_object_index_header_by_name_v(
if (objix_hdr.p_hdr.span_ix == 0 && if (objix_hdr.p_hdr.span_ix == 0 &&
(objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) == (objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) { (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
if (strcmp((char *)user_p, (char *)objix_hdr.name) == 0) { if (strncmp((char *)user_p, (char *)objix_hdr.name, SPIFFS_OBJ_NAME_LEN) == 0) {
return SPIFFS_OK; return SPIFFS_OK;
} }
} }
@ -1715,7 +1715,7 @@ static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id i
if (objix_hdr.p_hdr.span_ix == 0 && if (objix_hdr.p_hdr.span_ix == 0 &&
(objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) == (objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) { (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
if (strcmp((char *)user_p, (char *)objix_hdr.name) == 0) { if (strncmp((char *)user_p, (char *)objix_hdr.name, SPIFFS_OBJ_NAME_LEN) == 0) {
return SPIFFS_ERR_CONFLICTING_NAME; return SPIFFS_ERR_CONFLICTING_NAME;
} }
} }
@ -1745,7 +1745,7 @@ static s32_t spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id
((objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_DELET)) == ((objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_DELET)) ==
(SPIFFS_PH_FLAG_DELET))) { (SPIFFS_PH_FLAG_DELET))) {
// ok object look up entry // ok object look up entry
if (state->conflicting_name && strcmp((const char *)state->conflicting_name, (char *)objix_hdr.name) == 0) { if (state->conflicting_name && strncmp((const char *)state->conflicting_name, (char *)objix_hdr.name, SPIFFS_OBJ_NAME_LEN) == 0) {
return SPIFFS_ERR_CONFLICTING_NAME; return SPIFFS_ERR_CONFLICTING_NAME;
} }