summaryrefslogtreecommitdiff
path: root/src/output
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-01 21:51:21 -0500
committermidipix <writeonce@midipix.org>2016-11-10 23:35:29 -0500
commit6025fbae177892720c7342f5e16d81545b0fba41 (patch)
tree7a7e8638debf11877a041610219ca3990773831e /src/output
parent7d4d3d88474a3ca002d2649094b92de63f184691 (diff)
downloadperk-6025fbae177892720c7342f5e16d81545b0fba41.tar.bz2
perk-6025fbae177892720c7342f5e16d81545b0fba41.tar.xz
output: forward stdio return values, act on failure.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/pe_output_export_symbols.c25
-rw-r--r--src/output/pe_output_import_libraries.c38
2 files changed, 35 insertions, 28 deletions
diff --git a/src/output/pe_output_export_symbols.c b/src/output/pe_output_export_symbols.c
index e6f4d5c..4ff8d57 100644
--- a/src/output/pe_output_export_symbols.c
+++ b/src/output/pe_output_export_symbols.c
@@ -8,18 +8,19 @@
#include <perk/perk_output.h>
#include "perk_output_impl.h"
-static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
+static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
{
- if (cctx->fmtflags & PERK_PRETTY_YAML)
- fputs("exports:\n",fout);
+ return (cctx->fmtflags & PERK_PRETTY_YAML)
+ ? fputs("exports:\n",fout)
+ : 0;
}
-static void pretty_export_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
+static int pretty_export_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
{
if (cctx->fmtflags & PERK_PRETTY_YAML)
- fprintf(fout,"- %s\n",name);
+ return fprintf(fout,"- %s\n",name);
else
- fprintf(fout,"%s\n",name);
+ return fprintf(fout,"%s\n",name);
}
int pe_output_export_symbols(
@@ -38,16 +39,18 @@ int pe_output_export_symbols(
if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
return -1;
- pretty_header(cctx,fout);
+ if ((pretty_header(cctx,fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
offset = m->hedata->virtual_addr - m->hedata->ptr_to_raw_data;
symrva = (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset));
for (i=0; i<m->edata.num_of_name_ptrs; i++)
- pretty_export_item(
- cctx,
- (char *)((uintptr_t)m->image.addr + symrva[i] - offset),
- fout);
+ if ((pretty_export_item(
+ cctx,
+ (char *)((uintptr_t)m->image.addr + symrva[i] - offset),
+ fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
return pe_output_epilog(0,ftmp);
}
diff --git a/src/output/pe_output_import_libraries.c b/src/output/pe_output_import_libraries.c
index 40d1a08..9a83780 100644
--- a/src/output/pe_output_import_libraries.c
+++ b/src/output/pe_output_import_libraries.c
@@ -8,30 +8,31 @@
#include <perk/perk_output.h>
#include "perk_output_impl.h"
-static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
+static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
{
- if (cctx->fmtflags & PERK_PRETTY_YAML)
- fputs("imports:\n",fout);
+ return (cctx->fmtflags & PERK_PRETTY_YAML)
+ ? fputs("imports:\n",fout)
+ : 0;
}
-static void pretty_implib_header(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
+static int pretty_implib_header(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
{
if ((cctx->fmtflags & PERK_PRETTY_YAML) && (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS))
- fprintf(fout," %s:\n",name);
+ return fprintf(fout," %s:\n",name);
else if (cctx->fmtflags & PERK_PRETTY_YAML)
- fprintf(fout,"- %s:\n",name);
+ return fprintf(fout,"- %s:\n",name);
else if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
- fprintf(fout,"%s:\n",name);
+ return fprintf(fout,"%s:\n",name);
else
- fprintf(fout,"%s\n",name);
+ return fprintf(fout,"%s\n",name);
}
-static void pretty_implib_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
+static int pretty_implib_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
{
if (cctx->fmtflags & PERK_PRETTY_YAML)
- fprintf(fout," - %s\n",name);
+ return fprintf(fout," - %s\n",name);
else
- fprintf(fout,"%s\n",name);
+ return fprintf(fout,"%s\n",name);
}
int pe_output_import_libraries(
@@ -48,18 +49,21 @@ int pe_output_import_libraries(
if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
return -1;
- pretty_header(cctx,fout);
+ if ((pretty_header(cctx,fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
for (i=0; i<m->summary.num_of_implibs; i++) {
- pretty_implib_header(cctx,m->idata[i].name,fout);
+ if ((pretty_implib_header(cctx,m->idata[i].name,fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
for (j=0; j<m->idata[i].count; j++)
if (m->idata[i].items[j].name)
- pretty_implib_item(
- cctx,
- m->idata[i].items[j].name,
- fout);
+ if ((pretty_implib_item(
+ cctx,
+ m->idata[i].items[j].name,
+ fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
}