提交 26dbe548 编写于 作者: R Richard Stanway

libobs: Check fwrite return value for extra safety

上级 925f72c8
...@@ -405,9 +405,15 @@ int config_save(config_t *config) ...@@ -405,9 +405,15 @@ int config_save(config_t *config)
} }
#ifdef _WIN32 #ifdef _WIN32
fwrite("\xEF\xBB\xBF", 1, 3, f); if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) {
fclose(f);
return CONFIG_ERROR;
}
#endif #endif
fwrite(str.array, 1, str.len, f); if (fwrite(str.array, str.len, 1, f) != 1) {
fclose(f);
return CONFIG_ERROR;
}
fclose(f); fclose(f);
pthread_mutex_unlock(&config->mutex); pthread_mutex_unlock(&config->mutex);
...@@ -444,6 +450,8 @@ int config_save_safe(config_t *config, const char *temp_ext, ...@@ -444,6 +450,8 @@ int config_save_safe(config_t *config, const char *temp_ext,
config->file = file; config->file = file;
if (ret != CONFIG_SUCCESS) { if (ret != CONFIG_SUCCESS) {
blog(LOG_ERROR, "config_save_safe: failed to "
"write to %s", temp_file.array);
goto cleanup; goto cleanup;
} }
......
...@@ -262,10 +262,19 @@ bool os_quick_write_utf8_file(const char *path, const char *str, size_t len, ...@@ -262,10 +262,19 @@ bool os_quick_write_utf8_file(const char *path, const char *str, size_t len,
if (!f) if (!f)
return false; return false;
if (marker) if (marker) {
fwrite("\xEF\xBB\xBF", 1, 3, f); if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) {
if (len) fclose(f);
fwrite(str, 1, len, f); return false;
}
}
if (len) {
if (fwrite(str, len, 1, f) != 1) {
fclose(f);
return false;
}
}
fflush(f); fflush(f);
fclose(f); fclose(f);
...@@ -292,6 +301,8 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str, ...@@ -292,6 +301,8 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str,
dstr_cat(&temp_path, temp_ext); dstr_cat(&temp_path, temp_ext);
if (!os_quick_write_utf8_file(temp_path.array, str, len, marker)) { 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; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册