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

libobs: Check fwrite return value for extra safety

上级 925f72c8
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册