mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-03 04:34:31 +02:00
Merge branch 'bugfix/return_EINVAL_if_truncate_length_minus_zero' into 'master'
fatfs: return EINVAL if truncate length is less than 0 Closes IDFCI-390 See merge request espressif/esp-idf!11980
This commit is contained in:
@@ -261,7 +261,7 @@ void test_fatfs_truncate_file(const char* filename)
|
||||
TEST_ASSERT_EQUAL(errno, EPERM);
|
||||
|
||||
TEST_ASSERT_EQUAL(-1, truncate(filename, -1));
|
||||
TEST_ASSERT_EQUAL(errno, EPERM);
|
||||
TEST_ASSERT_EQUAL(errno, EINVAL);
|
||||
|
||||
|
||||
// Truncating should succeed
|
||||
@@ -294,7 +294,7 @@ void test_fatfs_truncate_file(const char* filename)
|
||||
TEST_ASSERT_EQUAL(EPERM, errno);
|
||||
|
||||
TEST_ASSERT_EQUAL(-1, truncate(filename, -1));
|
||||
TEST_ASSERT_EQUAL(EPERM, errno);
|
||||
TEST_ASSERT_EQUAL(EINVAL, errno);
|
||||
|
||||
|
||||
// Truncating a truncated file should succeed
|
||||
|
@@ -882,12 +882,18 @@ static int vfs_fat_access(void* ctx, const char *path, int amode)
|
||||
static int vfs_fat_truncate(void* ctx, const char *path, off_t length)
|
||||
{
|
||||
FRESULT res;
|
||||
FIL* file;
|
||||
FIL* file = NULL;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
vfs_fat_ctx_t* fat_ctx = (vfs_fat_ctx_t*) ctx;
|
||||
|
||||
if (length < 0) {
|
||||
errno = EINVAL;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
_lock_acquire(&fat_ctx->lock);
|
||||
prepend_drive_to_path(fat_ctx, &path, NULL);
|
||||
|
||||
|
Reference in New Issue
Block a user