mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 04:42:18 +02:00
libobs: Check fwrite return value for extra safety
This commit is contained in:
parent
925f72c8c3
commit
26dbe54896
@ -405,9 +405,15 @@ int config_save(config_t *config)
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
fwrite("\xEF\xBB\xBF", 1, 3, f);
|
||||
if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) {
|
||||
fclose(f);
|
||||
return CONFIG_ERROR;
|
||||
}
|
||||
#endif
|
||||
fwrite(str.array, 1, str.len, f);
|
||||
if (fwrite(str.array, str.len, 1, f) != 1) {
|
||||
fclose(f);
|
||||
return CONFIG_ERROR;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
pthread_mutex_unlock(&config->mutex);
|
||||
@ -444,6 +450,8 @@ int config_save_safe(config_t *config, const char *temp_ext,
|
||||
config->file = file;
|
||||
|
||||
if (ret != CONFIG_SUCCESS) {
|
||||
blog(LOG_ERROR, "config_save_safe: failed to "
|
||||
"write to %s", temp_file.array);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -262,10 +262,19 @@ bool os_quick_write_utf8_file(const char *path, const char *str, size_t len,
|
||||
if (!f)
|
||||
return false;
|
||||
|
||||
if (marker)
|
||||
fwrite("\xEF\xBB\xBF", 1, 3, f);
|
||||
if (len)
|
||||
fwrite(str, 1, len, f);
|
||||
if (marker) {
|
||||
if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (len) {
|
||||
if (fwrite(str, len, 1, f) != 1) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fflush(f);
|
||||
fclose(f);
|
||||
|
||||
@ -292,6 +301,8 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str,
|
||||
dstr_cat(&temp_path, temp_ext);
|
||||
|
||||
if (!os_quick_write_utf8_file(temp_path.array, str, len, marker)) {
|
||||
blog(LOG_ERROR, "os_quick_write_utf8_file_safe: failed to "
|
||||
"write to %s", temp_path.array);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user