more consistent use of checks of BLI_open(), check 'fd < 0' rather then -1. packedfile incorrectly treated 0 as an error value. best not be vague/sloppy with this.
This commit is contained in:
@@ -816,7 +816,7 @@ int BKE_undo_save_file(const char *filename)
|
|||||||
* to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
|
* to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
file = BLI_open(filename, flag, 0666);
|
file = BLI_open(filename, flag, 0666);
|
||||||
if (file == -1) {
|
if (file < 0) {
|
||||||
if (errno == EEXIST) {
|
if (errno == EEXIST) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
file = BLI_open(filename, flag & ~O_CREAT, 0666);
|
file = BLI_open(filename, flag & ~O_CREAT, 0666);
|
||||||
|
@@ -597,7 +597,8 @@ Image *BKE_image_load(Main *bmain, const char *filepath)
|
|||||||
|
|
||||||
/* exists? */
|
/* exists? */
|
||||||
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
||||||
if (file == -1) return NULL;
|
if (file < 0)
|
||||||
|
return NULL;
|
||||||
close(file);
|
close(file);
|
||||||
|
|
||||||
/* create a short library name */
|
/* create a short library name */
|
||||||
|
@@ -625,7 +625,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
|
|||||||
|
|
||||||
/* exists? */
|
/* exists? */
|
||||||
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
||||||
if (file == -1)
|
if (file < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
close(file);
|
close(file);
|
||||||
|
|
||||||
|
@@ -202,7 +202,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
|
|||||||
* and create a PackedFile structure */
|
* and create a PackedFile structure */
|
||||||
|
|
||||||
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
|
file = BLI_open(name, O_BINARY | O_RDONLY, 0);
|
||||||
if (file <= 0) {
|
if (file < 0) {
|
||||||
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path '%s' not found", name);
|
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path '%s' not found", name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -327,20 +327,21 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i
|
|||||||
BLI_make_existing_file(name);
|
BLI_make_existing_file(name);
|
||||||
|
|
||||||
file = BLI_open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
|
file = BLI_open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
|
||||||
if (file >= 0) {
|
if (file < 0) {
|
||||||
|
BKE_reportf(reports, RPT_ERROR, "Error creating file '%s'", name);
|
||||||
|
ret_value = RET_ERROR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (write(file, pf->data, pf->size) != pf->size) {
|
if (write(file, pf->data, pf->size) != pf->size) {
|
||||||
BKE_reportf(reports, RPT_ERROR, "Error writing file '%s'", name);
|
BKE_reportf(reports, RPT_ERROR, "Error writing file '%s'", name);
|
||||||
ret_value = RET_ERROR;
|
ret_value = RET_ERROR;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
BKE_reportf(reports, RPT_INFO, "Saved packed file to: %s", name);
|
BKE_reportf(reports, RPT_INFO, "Saved packed file to: %s", name);
|
||||||
|
}
|
||||||
|
|
||||||
close(file);
|
close(file);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
BKE_reportf(reports, RPT_ERROR, "Error creating file '%s'", name);
|
|
||||||
ret_value = RET_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remove_tmp) {
|
if (remove_tmp) {
|
||||||
if (ret_value == RET_ERROR) {
|
if (ret_value == RET_ERROR) {
|
||||||
|
@@ -72,7 +72,7 @@ int BLO_is_a_runtime(const char *path)
|
|||||||
int datastart;
|
int datastart;
|
||||||
char buf[8];
|
char buf[8];
|
||||||
|
|
||||||
if (fd == -1)
|
if (fd < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
lseek(fd, -12, SEEK_END);
|
lseek(fd, -12, SEEK_END);
|
||||||
@@ -104,7 +104,7 @@ BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
|
|||||||
|
|
||||||
fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
|
fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd < 0) {
|
||||||
BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno));
|
BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@@ -3396,7 +3396,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
|
|||||||
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
|
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
|
||||||
|
|
||||||
file = BLI_open(tempname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
|
file = BLI_open(tempname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
|
||||||
if (file == -1) {
|
if (file < 0) {
|
||||||
BKE_reportf(reports, RPT_ERROR, "Cannot open file %s for writing: %s", tempname, strerror(errno));
|
BKE_reportf(reports, RPT_ERROR, "Cannot open file %s for writing: %s", tempname, strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user