Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request tojocky#254 from george-g/master
Browse files Browse the repository at this point in the history
Fix tojocky#216 printer.getPrinters() is not fail-safe
  • Loading branch information
tojocky authored Jun 24, 2019
2 parents dff584d + 7b77c5b commit c35bc17
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/node_printer_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,21 @@ namespace{
{
std::string error_str("Error on allocating memory for jobs: ");
error_str += getLastErrorCodeAndMessage();
return error_str;
v8::Local<v8::Object> result_printer_job = V8_VALUE_NEW_DEFAULT_V_0_11_10(Object);
result_printer_job->Set(V8_STRING_NEW_UTF8("error"), V8_STRING_NEW_UTF8(error_str.c_str()));
result_printer_jobs->Set(0, result_printer_job);
return std::string("");
}
DWORD dummy_bytes = 0;
bError = EnumJobsW(*iPrinterHandle, 0, iTotalJobs, 2, (LPBYTE)jobs.get(), bytes_needed, &dummy_bytes, &totalJobs);
if(!bError)
{
std::string error_str("Error on EnumJobsW: ");
error_str += getLastErrorCodeAndMessage();
return error_str;
v8::Local<v8::Object> result_printer_job = V8_VALUE_NEW_DEFAULT_V_0_11_10(Object);
result_printer_job->Set(V8_STRING_NEW_UTF8("error"), V8_STRING_NEW_UTF8(error_str.c_str()));
result_printer_jobs->Set(0, result_printer_job);
return std::string("");
}
JOB_INFO_2W *job = jobs.get();
for(DWORD i = 0; i < totalJobs; ++i, ++job)
Expand Down

0 comments on commit c35bc17

Please sign in to comment.