]> git.siccegge.de Git - frida/frida.git/commitdiff
Do proper errorhandling for fileload
authorChristoph Egger <christoph@christoph-egger.org>
Mon, 25 May 2015 05:37:00 +0000 (07:37 +0200)
committerChristoph Egger <christoph@christoph-egger.org>
Mon, 25 May 2015 05:37:00 +0000 (07:37 +0200)
Sharing code with evaluation of strings, now proper error handling is
done and frida won't crash if an invalid scheme file is loaded.

src/bindings/Guile.cxx
src/bindings/Guile.hxx

index d4295c475411d2ae939c1dc0925c5f955938c200..863c9ccd23e43ecdbd3716d6b5ef9b9e6af387d7 100644 (file)
@@ -32,14 +32,14 @@ GuileInterpreter::GuileInterpreter()
        LOG4CXX_INFO(logger, "Initializing GUILE finished");
 }
 
-int GuileInterpreter::evaluate(const std::string& command,
-                               std::ostream& stdout,
-                               std::ostream& stderr,
-                               std::string& result) {
-
+int GuileInterpreter::evaluateWithErrorHandling(SCM (*fun)(void *),
+                                                void* data,
+                                                std::ostream& stdout,
+                                                std::ostream& stderr,
+                                                std::string& result) {
        SCM result_obj = scm_internal_catch(SCM_BOOL_T,
-                                           (SCM (*)(void *))scm_c_eval_string,
-                                           (void*)command.c_str(),
+                                           fun,
+                                           data,
                                            handler, NULL);
 
        SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
@@ -54,16 +54,28 @@ int GuileInterpreter::evaluate(const std::string& command,
 
        scm_truncate_file(guile_output_port, scm_from_uint16(0));
        scm_truncate_file(guile_error_port, scm_from_uint16(0));
-
        return 0;
 }
 
+int GuileInterpreter::evaluate(const std::string& command,
+                               std::ostream& stdout,
+                               std::ostream& stderr,
+                               std::string& result) {
+
+       return evaluateWithErrorHandling((SCM (*)(void *))scm_c_eval_string,
+                                        (void*)command.c_str(),
+                                        stdout, stderr, result);
+
+}
+
 int GuileInterpreter::loadFile(const std::string& filename,
                                std::ostream& stdout,
                                std::ostream& stderr,
                                std::string& result) {
-       LOG4CXX_INFO(logger, "Loading file \"" << filename << "\"");
-       scm_c_primitive_load(filename.c_str());
-       LOG4CXX_INFO(logger, "Finished file \"" << filename << "\"");
+       LOG4CXX_DEBUG(logger, "Loading file \"" << filename << "\"");
+       evaluateWithErrorHandling((SCM (*)(void *))scm_c_primitive_load,
+                                        (void*)filename.c_str(),
+                                        stdout, stderr, result);
+       LOG4CXX_DEBUG(logger, "Finished file \"" << filename << "\"");
        return 0;
 }
index 942b04ff9ab00561f8c47dbdb4cad8946ca850f2..612f33bdfb1fb6b6170bf6d67caff9392b1ba93b 100644 (file)
@@ -25,6 +25,12 @@ public:
 
        std::string fileExtension() const {return "scm";}
 private:
+       int evaluateWithErrorHandling(SCM (*fun)(void *),
+                                     void* data,
+                                     std::ostream& stdout,
+                                     std::ostream& stderr,
+                                     std::string& result);
+
        SCM guile_output_port;
        SCM guile_error_port;
        log4cxx::LoggerPtr logger;