Updated attached patch, line 206 now reads: efree (&ret); -- felix On Tuesday 10 November 2009 09:40:59 Felix Wolfsteller wrote: > Hi Christian, > thanks for the patch. > Looks good to me, except for style (refer to > http://www.openvas.org/compendium/source-code-style-guide.html) and three > memleaks, if i am not mistaken: > (1) (translate_vhost) variable "temp" was not freed. > (2) (target_file_to_list) "ret" lost. > (3) (target_translate) "s_wo_white" lost. > Also, in that file, usage of char* and gchar* is mixed, which should > generally be avoided. I did not make any changes to that (neither did you, > it was like that before). > > I was about to commit a modified version of your changes, but did not > want/could not test. The patch is attached, please review. > > Feel free to join http://wald.intevation.org/projects/openvas/ and request > commit rights. > > enjoy > -- felix > > On Tuesday 10 November 2009 05:42:26 Christian Kuersteiner wrote: > > Hello, > > > > I created a small patch for the OpenVAS Client to allow entering of > > virtual hosts in the format ip[vhost1,vhost2]. It should work both in > > gui and cli mode. > > The next part will be to group the report accordingly. > > > > Please feel free to comment or commit it :-) > > > > BR, > > > > Christian
-- Felix Wolfsteller | ++49 541 335083-783 | http://www.intevation.de/ PGP Key: 39DE0100 Intevation GmbH, Neuer Graben 17, 49074 Osnabrück | AG Osnabrück, HR B 18998 Geschäftsführer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner
Index: openvas/read_target_file.c =================================================================== --- openvas/read_target_file.c (revision 5826) +++ openvas/read_target_file.c (working copy) @@ -104,6 +104,38 @@ /** + * @brief Convert target string with virtual hosts to comma separated string. + * + * This function translates a string from the format + * IP[virtual_host1,virtual host2, ...] to a string in the format + * IP,virtual_host1,virtual host2,... + * It has to be called from every function which reads targets in. + * + * @param targets Target string with possible virtual hosts in it. + * + * @return New comma separated target string with virtual hosts as targets. + */ +static char* +translate_vhosts (const char* targets) +{ + gchar * temp = g_strdup (targets); + gchar ** v_wo_bracket = NULL; + gchar * s_wo_bracket = NULL; + + // Strip out '[' and replace it with a comma. + g_strdelimit (temp, "[", ','); + + // Delete the character ']' entirely. + v_wo_bracket = g_strsplit (temp, "]", -1); + s_wo_bracket = g_strjoinv (NULL, v_wo_bracket); + + g_free (temp); + g_strfreev (v_wo_bracket); + return s_wo_bracket; +} + + +/** * @brief Returns a string assembled out of the lines in file filename. * * The string will contain all the content of the file where newlines have been @@ -122,6 +154,7 @@ int len; struct_stat sb; int n, offs, left ; + gchar* result = NULL; if(fd < 0) { @@ -166,7 +199,12 @@ ret[len-1]='\0'; len--; } - return(ret); + + // Strip out the virtual hosts. + result = translate_vhosts (ret); + + efree (&ret); + return (result); } @@ -188,6 +226,7 @@ { char* untouched = NULL; gchar* s_wo_white = NULL; + gchar* result = NULL; gchar** v_wo_white; // Get untouched list of targets @@ -202,9 +241,13 @@ // Collapse the vector. s_wo_white = g_strjoinv (NULL, v_wo_white); + // strip out the virtual hosts + result = translate_vhosts (s_wo_white); + // Free and return g_strfreev (v_wo_white); - return s_wo_white; + g_free (s_wo_white); + return result; } /**
_______________________________________________ Openvas-devel mailing list Openvas-devel@wald.intevation.org http://lists.wald.intevation.org/mailman/listinfo/openvas-devel