[Openvas-commits] r6062 - in trunk/openvas-libraries: . nasl

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Dec 4 12:32:24 CET 2009


Author: mwiegand
Date: 2009-12-04 12:32:23 +0100 (Fri, 04 Dec 2009)
New Revision: 6062

Modified:
   trunk/openvas-libraries/ChangeLog
   trunk/openvas-libraries/nasl/exec.c
Log:
* nasl/exec.c (exec_nasl_script): Fixed a potential memory leak,
improved error handling, made glib usage more consistent, clarified
return value in documentation.


Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog	2009-12-04 10:05:55 UTC (rev 6061)
+++ trunk/openvas-libraries/ChangeLog	2009-12-04 11:32:23 UTC (rev 6062)
@@ -1,5 +1,11 @@
 2009-12-04  Michael Wiegand <michael.wiegand at intevation.de>
 
+	* nasl/exec.c (exec_nasl_script): Fixed a potential memory leak,
+	improved error handling, made glib usage more consistent, clarified
+	return value in documentation.
+
+2009-12-04  Michael Wiegand <michael.wiegand at intevation.de>
+
 	Add support for defining one additional directory on the command line
 	which will be used to look for includes to openvas-nasl.
 

Modified: trunk/openvas-libraries/nasl/exec.c
===================================================================
--- trunk/openvas-libraries/nasl/exec.c	2009-12-04 10:05:55 UTC (rev 6061)
+++ trunk/openvas-libraries/nasl/exec.c	2009-12-04 11:32:23 UTC (rev 6062)
@@ -19,10 +19,10 @@
 
 #include <stdlib.h> /* for srand48 */
 #include <string.h> /* for strlen */
-#include <sys/param.h> /* for MAXPATHLEN */
 #include <unistd.h> /* for getpid */
 
-#include <glib.h>
+#include <glib.h> /* for g_get_current_dir and others */
+#include <glib/gstdio.h> /* for g_chdir */
 
 #include "system.h" /* for efree */
 
@@ -1755,7 +1755,8 @@
  * @param mode         Bit field describing launch mode (description, parse
  *                     always signed).
  *
- * @return Values < 0
+ * @return 0 if the script was executed successfully, negative values if an
+ * error occurred.
  */
 int
 exec_nasl_script (struct arglist * script_infos, const char* name, int mode)
@@ -1765,8 +1766,8 @@
   int         err = 0;
   tree_cell   *ret;
   lex_ctxt    *lexic;
-  char        old_dir[MAXPATHLEN+1];
-  char        *newdir;
+  gchar      *old_dir;
+  gchar      *newdir;
   char        *old;
   tree_cell   tc;
   struct arglist* prefs = arg_get_value (script_infos, "preferences");
@@ -1775,7 +1776,7 @@
 
   srand48(getpid() + getppid() + (long)time(NULL));
 
-  g_snprintf (old_dir, MAXPATHLEN, "%s", g_get_current_dir ());
+  old_dir = g_get_current_dir ();
 
 #if NASL_DEBUG > 2
   nasl_trace_fp = stderr;
@@ -1790,7 +1791,12 @@
 
  newdir = g_path_get_basename (name);
 
- chdir (newdir);
+ if (g_chdir (newdir) != 0)
+   {
+     g_free (old_dir);
+     g_free (newdir);
+     return -1;
+   }
  g_free (newdir);
 
   bzero (&ctx, sizeof(ctx));
@@ -1799,7 +1805,8 @@
 
  if (nasl_reload_or_parse(&ctx, name) < 0)
   {
-    chdir(old_dir);
+    g_chdir(old_dir);
+    g_free (old_dir);
     return -1;
   }
 
@@ -1890,6 +1897,12 @@
 #endif
 
  chdir (old_dir);
+ if (g_chdir (old_dir) != 0)
+   {
+     g_free (old_dir);
+     return -1;
+   }
+ g_free (old_dir);
  if (mode & NASL_EXEC_DONT_CLEANUP)
    return err;
 



More information about the Openvas-commits mailing list