[Openvas-commits] r5755 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Oct 29 12:52:15 CET 2009


Author: mattm
Date: 2009-10-29 12:52:09 +0100 (Thu, 29 Oct 2009)
New Revision: 5755

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/lsc_user.c
   trunk/openvas-manager/src/lsc_user.h
   trunk/openvas-manager/src/manage.c
   trunk/openvas-manager/src/manage.h
   trunk/openvas-manager/src/omp.c
   trunk/openvas-manager/src/openvasmd.c
   trunk/openvas-manager/src/ovas-mngr-comm.c
   trunk/openvas-manager/src/oxpd.h
   trunk/openvas-manager/src/splint.h
   trunk/openvas-manager/src/tasks_sql.h
Log:
	Cleanup after static analysis.

	* src/ovas-mngr-comm.c (sendf_to_server): Declare variables at start of
	block.

	* src/tasks_sql.h: Include splint.h.  Move variable declarations to block
	starts.  Mark /*@unused@*/ params.  Work around cpp string concatenation
	for splint.
	(init_manage): Free database_version.
	(make_task_rcfile): Remove name variable.
	(clude): Free formatted in same place as other prepare loops.
	(create_lsc_credential): Free rand and formatted.

	* src/splint.h: Include gnutls.h and uuid.h.
	(g_malloc, g_malloc0): Update types.
	(g_dir_read_name, g_dir_close, g_rand_new, g_rand_free): New headers.

	* src/oxpd.h (from_buffer_size): Add extern.

	* src/lsc_user.c: Include splint.h.  Move variable declarations to block
	starts.
	(file_utils_rmdir_rf): Check error before using it.  Free g_build_filename
	return.
	(file_utils_copy_file): Change bytes_written to a size_t.  Check error
	before using it.
	(ssh_privkey_create, ssh_pubkey_create): Free command.
	(get_rpm_generator_path): Make return const.
	(lsc_user_rpm_create): Make oltap_path const.

	* src/lsc_user.h (lsc_user_all_create): Remove param names.

	* src/manage.c: Move variable declarations to block starts.
	(delete_reports): Cleanup iterator afterwards.
	(start_task): Free hosts.

	* src/manage.h [!TASKS_SQL]: Add dummy declarations for splint.
	(host_iterator_end_time): Remove duplicate declaration.

	* src/omp.c: Move variable declarations to block starts.  Mark
	/*@unused@*/ params.
	(send_nvt): Work around macro for splint.
	(print_report_xml): Use fputs instead of fprintf for fixed string.
	(print_report_latex): Add RATS comments about fprintf args.
	(omp_xml_handle_end_element): Add RATS comments about system args.
	Remove duplicate free of description.

	* src/openvasmd.c: Move variable declarations to block starts.  Mark
	/*@unused@*/ params.
	(accept_and_maybe_fork): Add RATS comment about signal arg.
	(main): Use char syntax for char literal 0.  Free option_context.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/ChangeLog	2009-10-29 11:52:09 UTC (rev 5755)
@@ -1,5 +1,58 @@
 2009-10-29  Matthew Mundell <matthew.mundell at intevation.de>
 
+	Cleanup after static analysis.
+
+	* src/ovas-mngr-comm.c (sendf_to_server): Declare variables at start of
+	block.
+
+	* src/tasks_sql.h: Include splint.h.  Move variable declarations to block
+	starts.  Mark /*@unused@*/ params.  Work around cpp string concatenation
+	for splint.
+	(init_manage): Free database_version.
+	(make_task_rcfile): Remove name variable.
+	(clude): Free formatted in same place as other prepare loops.
+	(create_lsc_credential): Free rand and formatted.
+
+	* src/splint.h: Include gnutls.h and uuid.h.
+	(g_malloc, g_malloc0): Update types.
+	(g_dir_read_name, g_dir_close, g_rand_new, g_rand_free): New headers.
+
+	* src/oxpd.h (from_buffer_size): Add extern.
+
+	* src/lsc_user.c: Include splint.h.  Move variable declarations to block
+	starts.
+	(file_utils_rmdir_rf): Check error before using it.  Free g_build_filename
+	return.
+	(file_utils_copy_file): Change bytes_written to a size_t.  Check error
+	before using it.
+	(ssh_privkey_create, ssh_pubkey_create): Free command.
+	(get_rpm_generator_path): Make return const.
+	(lsc_user_rpm_create): Make oltap_path const.
+
+	* src/lsc_user.h (lsc_user_all_create): Remove param names.
+
+	* src/manage.c: Move variable declarations to block starts.
+	(delete_reports): Cleanup iterator afterwards.
+	(start_task): Free hosts.
+
+	* src/manage.h [!TASKS_SQL]: Add dummy declarations for splint.
+	(host_iterator_end_time): Remove duplicate declaration.
+
+	* src/omp.c: Move variable declarations to block starts.  Mark
+	/*@unused@*/ params.
+	(send_nvt): Work around macro for splint.
+	(print_report_xml): Use fputs instead of fprintf for fixed string.
+	(print_report_latex): Add RATS comments about fprintf args.
+	(omp_xml_handle_end_element): Add RATS comments about system args.
+	Remove duplicate free of description.
+
+	* src/openvasmd.c: Move variable declarations to block starts.  Mark
+	/*@unused@*/ params.
+	(accept_and_maybe_fork): Add RATS comment about signal arg.
+	(main): Use char syntax for char literal 0.  Free option_context.
+
+2009-10-29  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/otp.c (process_otp_scanner_input): Add RATS comments about sscanf
 	field lengths.  Put a fullstop on a comment.
 

Modified: trunk/openvas-manager/src/lsc_user.c
===================================================================
--- trunk/openvas-manager/src/lsc_user.c	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/lsc_user.c	2009-10-29 11:52:09 UTC (rev 5755)
@@ -35,6 +35,10 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#ifdef S_SPLINT_S
+#include "splint.h"
+#endif
+
 #undef G_LOG_DOMAIN
 /**
  * @brief GLib log domain.
@@ -129,8 +133,11 @@
 
       if (directory == NULL)
         {
-          g_warning ("g_dir_open(%s) failed - %s\n", pathname, error->message);
-          g_error_free (error);
+          if (error)
+            {
+              g_warning ("g_dir_open(%s) failed - %s\n", pathname, error->message);
+              g_error_free (error);
+            }
           return -1;
         }
       else
@@ -138,11 +145,11 @@
           int ret = 0;
           const gchar *entry = NULL;
 
-          while ((entry = g_dir_read_name (directory)) && (ret == 0))
+          while ((entry = g_dir_read_name (directory)) != NULL && (ret == 0))
             {
-              ret = file_utils_rmdir_rf (g_build_filename (pathname,
-                                                           entry,
-                                                           NULL));
+              gchar *entry_path = g_build_filename (pathname, entry, NULL);
+              ret = file_utils_rmdir_rf (entry_path);
+              g_free (entry_path);
               if (ret != 0)
                 {
                   g_warning ("Failed to remove %s from %s!", entry, pathname);
@@ -175,19 +182,24 @@
 {
   gchar *src_file_content = NULL;
   gsize src_file_size = 0;
-  int bytes_written = 0;
+  size_t bytes_written = 0;
   FILE *fd = NULL;
   GError *error;
 
   /* Read file content into memory. */
 
   error = NULL;
-  g_file_get_contents (source_file, &src_file_content, &src_file_size, &error);
-  if (error)
+  if (g_file_get_contents (source_file,
+                           &src_file_content,
+                           &src_file_size,
+                           &error))
     {
-      g_debug ("%s: failed to read %s: %s",
-               __FUNCTION__, source_file, error->message);
-      g_error_free (error);
+      if (error)
+        {
+          g_debug ("%s: failed to read %s: %s",
+                   __FUNCTION__, source_file, error->message);
+          g_error_free (error);
+        }
       return FALSE;
     }
 
@@ -203,10 +215,10 @@
 
   /* Write content of src to dst and close it. */
 
-  bytes_written = fwrite (src_file_content, 1, src_file_size, fd);
+  bytes_written = fwrite (src_file_content, 1, (size_t) src_file_size, fd);
   fclose (fd);
 
-  if (bytes_written != src_file_size)
+  if (bytes_written != (size_t) src_file_size)
     {
       g_debug ("%s: failed to write to %s (%d/%d)",
                __FUNCTION__, dest_file, bytes_written, src_file_size);
@@ -281,6 +293,7 @@
   gint exit_status;
   gchar *dir = NULL;
   gchar *pubkey_stripped = NULL;
+  gchar *command;
 
   /* Sanity-check essential parameters. */
   if (!passphrase_pub || !passphrase_priv)
@@ -309,7 +322,7 @@
     }
   g_free (dir);
 
-  /* Strip ".pub" of public key filename, if any. */
+  /* Strip ".pub" off public key filename, if any. */
 
   if (g_str_has_suffix (pubkey_file, ".pub") == TRUE)
     {
@@ -323,7 +336,7 @@
 
   /* Spawn openssl. */
 
-  const gchar *command =
+  command =
     g_strconcat ("openssl pkcs8 -topk8 -v2 des3"
                  " -in ", pubkey_stripped,
                  " -passin pass:\"", passphrase_pub, "\"",
@@ -343,9 +356,11 @@
       g_debug ("%s: openssl failed with %d", __FUNCTION__, exit_status);
       g_debug ("%s: stdout: %s", __FUNCTION__, astdout);
       g_debug ("%s: stderr: %s", __FUNCTION__, astderr);
+      g_free (command);
       return -1;
     }
 
+  g_free (command);
   return 0;
 }
 
@@ -373,7 +388,7 @@
   gint exit_status = 0;
   gchar *dir;
   gchar *file_pubstripped;
-  const char *command;
+  char *command;
 
   /* Sanity-check essential parameters. */
 
@@ -443,8 +458,10 @@
                WEXITSTATUS (exit_status));
       g_debug ("%s: stdout: %s", __FUNCTION__, astdout);
       g_debug ("%s: stderr: %s", __FUNCTION__, astderr);
+      g_free (command);
       return -1;
     }
+  g_free (command);
   return 0;
 }
 
@@ -459,7 +476,7 @@
  * @return Newly allocated path to directory containing generator if found,
  *         else NULL.
  */
-static gchar *
+static const gchar *
 get_rpm_generator_path ()
 {
   static gchar *rpm_generator_path = NULL;
@@ -495,7 +512,7 @@
                      const gchar *public_key_path,
                      const gchar *to_filename)
 {
-  gchar *oltap_path;
+  const gchar *oltap_path;
   gchar *rpm_path = NULL;
   gint exit_status;
   gchar *new_pubkey_filename = NULL;
@@ -503,6 +520,9 @@
   gchar **cmd;
   char tmpdir[] = "/tmp/lsc_user_rpm_create_XXXXXX";
   gboolean success = TRUE;
+  gchar *standard_out;
+  gchar *standard_err;
+  gchar *rpmfile;
 
   oltap_path = get_rpm_generator_path ();
 
@@ -540,8 +560,6 @@
   cmd[4] = NULL;
   g_debug ("%s: Spawning in %s: %s %s %s %s\n",
            __FUNCTION__, oltap_path, cmd[0], cmd[1], cmd[2], cmd[3]);
-  gchar *standard_out;
-  gchar *standard_err;
   if ((g_spawn_sync (oltap_path,
                      cmd,
                      NULL,                  /* Environment. */
@@ -579,10 +597,10 @@
    * for example RPMS/noarch/openvas-lsc-target-example_user-0.5-1.noarch.rpm.
    */
 
-  gchar *rpmfile = g_strconcat ("openvas-lsc-target-",
-                                username,
-                                "-0.5-1.noarch.rpm",
-                                NULL);
+  rpmfile = g_strconcat ("openvas-lsc-target-",
+                         username,
+                         "-0.5-1.noarch.rpm",
+                         NULL);
   rpm_path = g_build_filename (tmpdir, rpmfile, NULL);
   g_debug ("%s: new filename (rpm_path): %s\n", __FUNCTION__, rpm_path);
 

Modified: trunk/openvas-manager/src/lsc_user.h
===================================================================
--- trunk/openvas-manager/src/lsc_user.h	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/lsc_user.h	2009-10-29 11:52:09 UTC (rev 5755)
@@ -31,12 +31,12 @@
 #include "openvas_ssh_login.h"
 
 int
-lsc_user_all_create (const gchar *name,
-                     const gchar *password,
-                     gchar **public_key,
-                     gchar **private_key,
-                     void **rpm, gsize *rpm_size,
-                     void **deb, gsize *deb_size,
-                     void **exe, gsize *exe_size);
+lsc_user_all_create (const gchar *,
+                     const gchar *,
+                     gchar **,
+                     gchar **,
+                     void **, gsize *,
+                     void **, gsize *,
+                     void **, gsize *);
 
 #endif /* _OPENVASMD_LSC_USER_H */

Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/manage.c	2009-10-29 11:52:09 UTC (rev 5755)
@@ -223,6 +223,7 @@
   // FIX wrap in transaction?
   init_report_iterator (&iterator, task);
   while (next_report (&iterator, &report)) delete_report (report);
+  cleanup_iterator (&iterator);
   return 0;
 }
 
@@ -692,12 +693,13 @@
   gchar *plugins;
   int fail;
   GSList *files = NULL;
+  task_status_t run_status;
 
   tracef ("   start task %u\n", task_id (task));
 
   // FIX atomic
 
-  task_status_t run_status = task_run_status (task);
+  run_status = task_run_status (task);
   if (run_status == TASK_STATUS_REQUESTED
       || run_status == TASK_STATUS_RUNNING
       || run_status == TASK_STATUS_STOP_REQUESTED
@@ -723,7 +725,11 @@
 
   /* Create the report. */
 
-  if (create_report (task, report_id)) return -3;
+  if (create_report (task, report_id))
+    {
+      free (hosts);
+      return -3;
+    }
 
   /* Reset any running information. */
 
@@ -731,13 +737,18 @@
 
   /* Send the preferences header. */
 
-  if (send_to_server ("CLIENT <|> PREFERENCES <|>\n")) return -1;
+  if (send_to_server ("CLIENT <|> PREFERENCES <|>\n"))
+    {
+      free (hosts);
+      return -1;
+    }
 
   /* Get the config and selector. */
 
   config = task_config (task);
   if (config == NULL)
     {
+      free (hosts);
       tracef ("   task config is NULL.\n");
       return -5;
     }
@@ -745,6 +756,7 @@
   selector = config_nvt_selector (config);
   if (selector == NULL)
     {
+      free (hosts);
       free (config);
       tracef ("   task config is NULL.\n");
       return -5;
@@ -765,22 +777,26 @@
 
   if (send_to_server ("ntp_keep_communication_alive <|> yes\n"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
   if (send_to_server ("ntp_client_accepts_notes <|> yes\n"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
   // FIX still getting FINISHED msgs
   if (send_to_server ("ntp_opt_show_end <|> no\n"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
   if (send_to_server ("ntp_short_status <|> no\n"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
@@ -789,17 +805,20 @@
 
   if (send_config_preferences (config, "SERVER_PREFS"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
   if (send_config_preferences (config, "PLUGINS_PREFS"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
 
   if (send_to_server ("<|> CLIENT\n"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
@@ -815,6 +834,7 @@
       GSList *last = files;
       if (send_task_file (task, files->data))
         {
+          free (hosts);
           free (config);
           /* Free the data. */
           while (files)
@@ -835,18 +855,24 @@
 
   if (send_to_server ("CLIENT <|> RULES <|>\n"))
     {
+      free (hosts);
       free (config);
       return -1;
     }
 
   if (send_config_rules (config))
     {
+      free (hosts);
       free (config);
       return -1;
     }
 
   free (config);
-  if (send_to_server ("<|> CLIENT\n")) return -1;
+  if (send_to_server ("<|> CLIENT\n"))
+    {
+      free (hosts);
+      return -1;
+    }
 
   /* Send the attack command. */
 
@@ -886,9 +912,10 @@
 int
 stop_task (task_t task)
 {
+  task_status_t run_status;
   tracef ("   request task stop %u\n", task_id (task));
   // FIX something should check safety credential before this
-  task_status_t run_status = task_run_status (task);
+  run_status = task_run_status (task);
   if (run_status == TASK_STATUS_REQUESTED
       || run_status == TASK_STATUS_RUNNING)
     {

Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/manage.h	2009-10-29 11:52:09 UTC (rev 5755)
@@ -101,7 +101,7 @@
 
 /* Task structures. */
 
-short scanner_active;
+extern short scanner_active;
 
 // FIX should be in otp.c/h
 /**
@@ -170,8 +170,25 @@
   sqlite3_stmt* stmt;
   gboolean done;
 } iterator_t;
-#endif /* TASKS_SQL */
+#else /* not TASKS_SQL */
+typedef long long int task_t;
+typedef long long int result_t;
+typedef long long int report_t;
+typedef long long int nvt_t;
 
+typedef struct
+{
+  void* stmt;
+  gboolean done;
+} task_iterator_t;
+
+typedef struct
+{
+  void* stmt;
+  gboolean done;
+} iterator_t;
+#endif /* not TASKS_SQL */
+
 
 /* Task global variables. */
 
@@ -496,9 +513,6 @@
 host_iterator_end_time (iterator_t*);
 
 const char*
-host_iterator_end_time (iterator_t*);
-
-const char*
 host_iterator_attack_state (iterator_t*);
 
 int

Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/omp.c	2009-10-29 11:52:09 UTC (rev 5755)
@@ -451,15 +451,17 @@
 
 #if 1
   /** @todo FIX Temp hack to catch ISO chars sent by scanner. */
-  gsize size_dummy;
-  gchar* msg_utf8 = msg ? g_convert (msg, strlen (msg),
-                                     "UTF-8", "ISO_8859-1",
-                                     NULL, &size_dummy, NULL)
-                        : NULL;
-  memmove (to_client + to_client_end, msg_utf8, strlen (msg_utf8));
-  tracef ("-> client: %s\n", msg_utf8);
-  to_client_end += strlen (msg_utf8);
-  g_free (msg_utf8);
+  {
+    gsize size_dummy;
+    gchar* msg_utf8 = msg ? g_convert (msg, strlen (msg),
+                                       "UTF-8", "ISO_8859-1",
+                                       NULL, &size_dummy, NULL)
+                          : NULL;
+    memmove (to_client + to_client_end, msg_utf8, strlen (msg_utf8));
+    tracef ("-> client: %s\n", msg_utf8);
+    to_client_end += strlen (msg_utf8);
+    g_free (msg_utf8);
+  }
 #else /* 1 */
   memmove (to_client + to_client_end, msg, strlen (msg));
   tracef ("-> client: %s\n", msg);
@@ -1582,7 +1584,7 @@
  * @return 0 if out of space in to_client buffer, else 1.
  */
 static gint
-send_certificate (gpointer cert_gp, gpointer dummy)
+send_certificate (gpointer cert_gp, /*@unused@*/ gpointer dummy)
 {
   certificate_t* cert = (certificate_t*) cert_gp;
   gchar* msg;
@@ -1720,12 +1722,14 @@
     {
       gsize dummy;
 
+#ifndef S_SPLINT_S
       DEF (copyright);
       DEF (description);
       DEF (summary);
       DEF (family);
       DEF (version);
       DEF (tag);
+#endif /* not S_SPLINT_S */
 
 #undef DEF
 
@@ -1922,10 +1926,10 @@
       return -1;
     }
 
-  fprintf (out,
-           "<get_report_response"
-           " status=\"" STATUS_OK "\" status_text=\"" STATUS_OK_TEXT "\">"
-           "<report>");
+  fputs ("<get_report_response"
+         " status=\"" STATUS_OK "\" status_text=\"" STATUS_OK_TEXT "\">"
+         "<report>",
+         out);
 
   start_time = scan_start_time (report);
   fprintf (out,
@@ -2307,6 +2311,7 @@
       total_notes += notes;
 
       num_hosts++;
+      /* RATS: ignore, argument 2 is a constant string. */
       fprintf (out,
                "\\hline\n"
                // FIX 0 (false positives)
@@ -2326,6 +2331,7 @@
     }
   cleanup_iterator (&hosts);
 
+  /* RATS: ignore, argument 2 is a constant string. */
   fprintf (out,
            "\\hline\n"
            // FIX 0 (false positives)
@@ -3185,6 +3191,7 @@
                             SEND_TO_CLIENT_OR_FAIL
                              (XML_INTERNAL_ERROR ("get_report"));
                           }
+                        /* RATS: ignore, command is defined above. */
                         else if (ret = system (command),
                                  // FIX ret is always -1
                                  0 && ((ret) == -1
@@ -3339,6 +3346,7 @@
                             SEND_TO_CLIENT_OR_FAIL
                              (XML_INTERNAL_ERROR ("get_report"));
                           }
+                        /* RATS: ignore, command is defined above. */
                         else if (ret = system (command),
                                  // FIX ret is always -1
                                  0 && ((ret) == -1
@@ -3438,12 +3446,12 @@
                   {
                     // TODO: Remove latex_file.
 
-                    close (latex_fd);
-
                     gchar *pdf_file, *command;
                     gint pdf_fd;
                     int ret;
 
+                    close (latex_fd);
+
                     // TODO: Remove pdf_file.
 
                     pdf_file = g_strdup (latex_file);
@@ -3475,6 +3483,7 @@
                         SEND_TO_CLIENT_OR_FAIL
                          (XML_INTERNAL_ERROR ("get_report"));
                       }
+                    /* RATS: ignore, command is defined above. */
                     else if (ret = system (command),
                              // FIX ret is always -1
                              0 && ((ret) == -1
@@ -3699,8 +3708,8 @@
       case CLIENT_DELETE_TASK:
         if (current_uuid)
           {
+            task_t task;
             assert (current_client_task == (task_t) 0);
-            task_t task;
             if (find_task (current_uuid, &task))
               SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("delete_task"));
             else if (task == 0)
@@ -3828,8 +3837,8 @@
         // FIX update to match create_task (config, target)
         if (current_uuid)
           {
+            task_t task;
             assert (current_client_task == (task_t) 0);
-            task_t task;
             if (find_task (current_uuid, &task))
               SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("modify_task"));
             else if (task == 0)
@@ -4322,7 +4331,6 @@
                 {
                   request_delete_task (&current_client_task);
                   g_free (target_name);
-                  g_free (description);
                   free (tsk_uuid);
                   SEND_TO_CLIENT_OR_FAIL
                    (XML_INTERNAL_ERROR ("create_task"));
@@ -4447,8 +4455,8 @@
       case CLIENT_START_TASK:
         if (current_uuid)
           {
+            task_t task;
             assert (current_client_task == (task_t) 0);
-            task_t task;
             if (find_task (current_uuid, &task))
               SEND_TO_CLIENT_OR_FAIL (XML_INTERNAL_ERROR ("start_task"));
             else if (task == 0)

Modified: trunk/openvas-manager/src/openvasmd.c
===================================================================
--- trunk/openvas-manager/src/openvasmd.c	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/openvasmd.c	2009-10-29 11:52:09 UTC (rev 5755)
@@ -359,10 +359,11 @@
 accept_and_maybe_fork ()
 {
   /* Accept the client connection. */
+  pid_t pid;
   struct sockaddr_in client_address;
-  client_address.sin_family = AF_INET;
   socklen_t size = sizeof (client_address);
   int client_socket;
+  client_address.sin_family = AF_INET;
   while ((client_socket = accept (manager_socket,
                                   (struct sockaddr *) &client_address,
                                   &size))
@@ -381,14 +382,17 @@
 
 #if FORK
   /* Fork a child to serve the client. */
-  pid_t pid = fork ();
+  pid = fork ();
   switch (pid)
     {
       case 0:
         /* Child. */
         {
+          int ret;
+
           is_parent = 0;
 
+          /* RATS: ignore, this is SIG_DFL damnit. */
           if (signal (SIGCHLD, SIG_DFL) == SIG_ERR)
             {
               g_critical ("%s: failed to set client SIGCHLD handler: %s\n",
@@ -414,7 +418,7 @@
               exit (EXIT_FAILURE);
             }
 #if FORK
-          int ret = serve_client (client_socket);
+          ret = serve_client (client_socket);
           /** @todo This should be done through libomp. */
           save_tasks ();
 #else
@@ -480,7 +484,7 @@
  * @param[in]  signal  The signal that caused this function to run.
  */
 void
-handle_sigterm (int signal)
+handle_sigterm (/*@unused@*/ int signal)
 {
   exit (EXIT_SUCCESS);
 }
@@ -491,7 +495,7 @@
  * @param[in]  signal  The signal that caused this function to run.
  */
 void
-handle_sighup (int signal)
+handle_sighup (/*@unused@*/ int signal)
 {
   exit (EXIT_SUCCESS);
 }
@@ -502,7 +506,7 @@
  * @param[in]  signal  The signal that caused this function to run.
  */
 void
-handle_sigint (int signal)
+handle_sigint (/*@unused@*/ int signal)
 {
   exit (EXIT_SUCCESS);
 }
@@ -550,7 +554,7 @@
         { "sport", 's', 0, G_OPTION_ARG_STRING, &scanner_port_string, "Scanner (openvassd) port number.", "<number>" },
         { "update", 'u', 0, G_OPTION_ARG_NONE, &update_nvt_cache, "Update the NVT cache and exit.", NULL },
         { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Print progress messages.", NULL },
-        { "version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print version and exit.", NULL },
+        { "version", '\0', 0, G_OPTION_ARG_NONE, &print_version, "Print version and exit.", NULL },
         { NULL }
       };
 
@@ -558,9 +562,11 @@
   g_option_context_add_main_entries (option_context, option_entries, NULL);
   if (!g_option_context_parse (option_context, &argc, &argv, &error))
     {
+      g_option_context_free (option_context);
       g_critical ("%s: %s\n\n", __FUNCTION__, error->message);
       exit (EXIT_FAILURE);
     }
+  g_option_context_free (option_context);
 
   if (print_version)
     {
@@ -1008,10 +1014,11 @@
    *     want to communicate with anything else here, like the scanner?
    */
 
-  int ret, nfds;
-  fd_set readfds, exceptfds;
   while (1)
     {
+      int ret, nfds;
+      fd_set readfds, exceptfds;
+
       FD_ZERO (&readfds);
       FD_SET (manager_socket, &readfds);
       FD_ZERO (&exceptfds);

Modified: trunk/openvas-manager/src/ovas-mngr-comm.c
===================================================================
--- trunk/openvas-manager/src/ovas-mngr-comm.c	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/ovas-mngr-comm.c	2009-10-29 11:52:09 UTC (rev 5755)
@@ -167,9 +167,11 @@
 sendf_to_server (const char* format, ...)
 {
   va_list args;
+  gchar* msg;
+  int ret;
   va_start (args, format);
-  gchar* msg = g_strdup_vprintf (format, args);
-  int ret = send_to_server (msg);
+  msg = g_strdup_vprintf (format, args);
+  ret = send_to_server (msg);
   g_free (msg);
   va_end (args);
   return ret;

Modified: trunk/openvas-manager/src/oxpd.h
===================================================================
--- trunk/openvas-manager/src/oxpd.h	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/oxpd.h	2009-10-29 11:52:09 UTC (rev 5755)
@@ -42,7 +42,7 @@
  */
 #define FROM_BUFFER_SIZE 1048576
 
-buffer_size_t from_buffer_size;
+extern buffer_size_t from_buffer_size;
 
 extern char from_client[];
 extern buffer_size_t from_client_start;

Modified: trunk/openvas-manager/src/splint.h
===================================================================
--- trunk/openvas-manager/src/splint.h	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/splint.h	2009-10-29 11:52:09 UTC (rev 5755)
@@ -35,11 +35,11 @@
 
 /*@only@*/
 gpointer
-g_malloc (gulong n_bytes);
+g_malloc (gsize n_bytes);
 
 /*@only@*/
 gpointer
-g_malloc0 (gulong n_bytes);
+g_malloc0 (gsize n_bytes);
 
 void
 g_free (/*@only@*/ /*@out@*/ /*@null@*/ gpointer mem);
@@ -100,9 +100,23 @@
 /*@notnull@*/ gchar*
 g_build_filename (const gchar *first, ...);
 
+/*@dependent@*/ const gchar*
+g_dir_read_name (GDir *dir);
+
+/*@dependent@*/ const gchar*
+g_dir_close (/*@only@*/ /*@out@*/ GDir *dir);
+
+/*@only@*/ GRand*
+g_rand_new (void);
+
+void
+g_rand_free (/*@only@*/ /*@out@*/ GRand *);
+
 
 /* UUIDS. */
 
+#include <ossp/uuid.h>
+
 /*@shared@*/ char*
 uuid_error (uuid_rc_t error);
 
@@ -119,6 +133,8 @@
 
 /* GNUTLS. */
 
+#include <gnutls/gnutls.h>
+
 /*@owned@*/ const char*
 gnutls_alert_get_name (gnutls_alert_description_t alert);
 

Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h	2009-10-29 11:31:54 UTC (rev 5754)
+++ trunk/openvas-manager/src/tasks_sql.h	2009-10-29 11:52:09 UTC (rev 5755)
@@ -29,6 +29,10 @@
 #include <openvas/openvas_logging.h>
 #include "lsc_user.h"
 
+#ifdef S_SPLINT_S
+#include "splint.h"
+#endif
+
 /**
  * @brief Version of the database schema.
  */
@@ -210,8 +214,8 @@
  * @return 0 success, 1 too few rows, -1 error.
  */
 int
-sql_x (unsigned int col, unsigned int row, char* sql, va_list args,
-       sqlite3_stmt** stmt_return)
+sql_x (/*@unused@*/ unsigned int col, unsigned int row, char* sql,
+       va_list args, sqlite3_stmt** stmt_return)
 {
   const char* tail;
   int ret;
@@ -283,15 +287,18 @@
 {
   sqlite3_stmt* stmt;
   va_list args;
+  int ret;
+
+  int sql_x_ret;
   va_start (args, sql);
-  int sql_x_ret = sql_x (col, row, sql, args, &stmt);
+  sql_x_ret = sql_x (col, row, sql, args, &stmt);
   va_end (args);
   if (sql_x_ret)
     {
       sqlite3_finalize (stmt);
       abort ();
     }
-  int ret = sqlite3_column_int (stmt, col);
+  ret = sqlite3_column_int (stmt, col);
   sqlite3_finalize (stmt);
   return ret;
 }
@@ -302,9 +309,11 @@
   sqlite3_stmt* stmt;
   const unsigned char* ret2;
   char* ret;
+  int sql_x_ret;
+
   va_list args;
   va_start (args, sql);
-  int sql_x_ret = sql_x (col, row, sql, args, &stmt);
+  sql_x_ret = sql_x (col, row, sql, args, &stmt);
   va_end (args);
   if (sql_x_ret)
     {
@@ -334,9 +343,11 @@
 sql_int64 (long long int* ret, unsigned int col, unsigned int row, char* sql, ...)
 {
   sqlite3_stmt* stmt;
+  int sql_x_ret;
   va_list args;
+
   va_start (args, sql);
-  int sql_x_ret = sql_x (col, row, sql, args, &stmt);
+  sql_x_ret = sql_x (col, row, sql, args, &stmt);
   va_end (args);
   switch (sql_x_ret)
     {
@@ -950,11 +961,11 @@
 append_to_task_string (task_t task, const char* field, const char* value)
 {
   char* current;
+  gchar* quote;
   current = sql_string (0, 0,
                         "SELECT %s FROM tasks WHERE ROWID = %llu;",
                         field,
                         task);
-  gchar* quote;
   if (current)
     {
       gchar* new = g_strconcat ((const gchar*) current, value, NULL);
@@ -1088,7 +1099,7 @@
     }
 
   /* Ensure the mgr directory exists. */
-  mgr_dir = g_build_filename (OPENVAS_STATE_DIR "/mgr/", NULL);
+  mgr_dir = g_build_filename (OPENVAS_STATE_DIR, "mgr", NULL);
   ret = g_mkdir_with_parents (mgr_dir, 0755 /* "rwxr-xr-x" */);
   g_free (mgr_dir);
   if (ret == -1)
@@ -1099,6 +1110,7 @@
       abort (); // FIX
     }
 
+#ifndef S_SPLINT_S
   /* Open the database. */
   if (sqlite3_open (database ? database
                              : OPENVAS_STATE_DIR "/mgr/tasks.db",
@@ -1109,6 +1121,7 @@
                  sqlite3_errmsg (task_db));
       abort (); // FIX
     }
+#endif /* not S_SPLINT_S */
 
   if (update_nvt_cache)
     {
@@ -1281,7 +1294,7 @@
 int
 init_manage (GSList *log_config, int nvt_cache_mode, const gchar *database)
 {
-  const char *database_version;
+  char *database_version;
   task_t index;
   task_iterator_t iterator;
 
@@ -1300,7 +1313,6 @@
   database_version = sql_string (0, 0,
                                  "SELECT value FROM meta"
                                  " WHERE name = 'database_version';");
-  /** @todo Free database_version. */
   if (nvt_cache_mode)
     {
       if (database_version
@@ -1312,14 +1324,18 @@
           g_message ("%s: database version supported by manager: %s\n",
                      __FUNCTION__,
                      G_STRINGIFY (DATABASE_VERSION));
+          g_free (database_version);
           return -2;
         }
+      g_free (database_version);
 
       /* If database_version was NULL then meta was missing, so assume
        * that the database is missing, which is OK. */
     }
   else
     {
+      long long int count;
+
       if (database_version)
         {
           if (strcmp (database_version, G_STRINGIFY (DATABASE_VERSION)))
@@ -1330,8 +1346,10 @@
               g_message ("%s: database version supported by manager: %s\n",
                          __FUNCTION__,
                          G_STRINGIFY (DATABASE_VERSION));
+              g_free (database_version);
               return -2;
             }
+          g_free (database_version);
         }
       else
         /* Assume database is missing. */
@@ -1343,7 +1361,6 @@
        * was created before NVT preferences were cached in the database.
        */
 
-      long long int count;
       if (sql_int64 (&count, 0, 0,
                      "SELECT count(*) FROM meta"
                      " WHERE name = 'nvts_md5sum'"
@@ -1957,7 +1974,7 @@
 int
 make_task_rcfile (task_t task)
 {
-  char *config, *target, *selector, *name, *hosts, *rc;
+  char *config, *target, *selector, *hosts, *rc;
   iterator_t prefs;
   GString *buffer;
 
@@ -1979,15 +1996,6 @@
       return -1;
     }
 
-  name = task_name (task);
-  if (name == NULL)
-    {
-      free (config);
-      free (target);
-      free (selector);
-      return -1;
-    }
-
   /* Header. */
 
   buffer = g_string_new ("# This file was automatically created"
@@ -3989,6 +3997,7 @@
     {
       ret = sqlite3_prepare (task_db, (char*) formatted, -1, &stmt, &tail);
       if (ret == SQLITE_BUSY) continue;
+      g_free (formatted);
       if (ret == SQLITE_OK)
         {
           if (stmt == NULL)
@@ -4091,7 +4100,6 @@
     }
 
   sqlite3_finalize (stmt);
-  g_free (formatted);
 }
 
 /**
@@ -4506,6 +4514,7 @@
 int
 config_in_use (const char* name)
 {
+  int ret;
   gchar* quoted_name;
 
   if (strcmp (name, "Full and fast") == 0
@@ -4515,9 +4524,9 @@
     return 1;
 
   quoted_name = sql_quote (name);
-  int ret = sql_int (0, 0,
-                     "SELECT count(*) FROM tasks WHERE config = '%s'",
-                     quoted_name);
+  ret = sql_int (0, 0,
+                 "SELECT count(*) FROM tasks WHERE config = '%s'",
+                 quoted_name);
   g_free (quoted_name);
   return ret;
 }
@@ -5274,11 +5283,13 @@
                              int all)
 {
   int ret;
+  gchar *quoted_family;
+  gchar *quoted_selector;
 
   if (all) return 1;
 
-  gchar *quoted_selector = sql_quote (selector);
-  gchar *quoted_family = sql_quote (family);
+  quoted_selector = sql_quote (selector);
+  quoted_family = sql_quote (family);
 
   ret = sql_int (0, 0,
                  "SELECT COUNT(*) FROM nvt_selectors"
@@ -5432,6 +5443,7 @@
   for (i = 0; i < PASSWORD_LENGTH - 1; i++)
     password[i] = (gchar) g_rand_int_range (rand, '0', 'z');
   password[PASSWORD_LENGTH - 1] = '\0';
+  g_rand_free (rand);
 
   if (lsc_user_all_create (name,
                            password,
@@ -5494,6 +5506,7 @@
       {
         ret = sqlite3_prepare (task_db, (char*) formatted, -1, &stmt, &tail);
         if (ret == SQLITE_BUSY) continue;
+        g_free (formatted);
         if (ret == SQLITE_OK)
           {
             if (stmt == NULL)



More information about the Openvas-commits mailing list