Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed start task failed #758

Merged
merged 2 commits into from Sep 27, 2019
Merged

fixed start task failed #758

merged 2 commits into from Sep 27, 2019

Conversation

b40yd
Copy link
Contributor

@b40yd b40yd commented Sep 27, 2019

  • issue
    fixed start a task failed.
    cannot start a task in alpine linux .
    python code:
  # -*- coding:utf-8 -*-

from gvm.connections import UnixSocketConnection
from gvm.errors import GvmError
from gvm.protocols.latest import Gmp
from gvm.transforms import EtreeCheckCommandTransform
from gvm.xml import pretty_print
import sys
import uuid

path = '/var/run/gvmd.sock'
connection = UnixSocketConnection(path=path)
transform = EtreeCheckCommandTransform()
gmp = Gmp(connection=connection, transform=transform)

username = 'admin'
password = 'admin'

try:
    tasks = []

    with gmp:
        gmp.authenticate(username, password)
        if not gmp.is_authenticated():
            print('not authenticate')

        tasks = gmp.get_tasks()
        for task in tasks.xpath('task'):
            task_id, = task.xpath("@id")
            print(task_id, task.find('name').text)
            pretty_print(gmp.start_task(task_id=task_id))

except GvmError as e:
    print('An error occurred', e, file=sys.stderr)
  • Tests
    Verify the problem.
#include <glib.h>
#include <stdio.h>

// use centos or other linux
/*
void
test_glib(const char *format, ...)
{
    gchar *formatted = NULL;
    va_list args;
    va_start (args, format);

    formatted = g_strdup_vprintf(format, args);
    printf("format: %d %s\n", len, formatted);
    va_end(args);
}
*/
// use vasprintf 
void
test_vasprintf(const char *format, ...)
{
    gint len;
    gchar *formatted = NULL;
    va_list args;
    va_start (args, format);
    len = vasprintf (&formatted, format, args);
    if (len < 0)
        formatted = NULL;
    printf("format: %d %s\n", len, formatted);
    va_end(args);
}

void 
main(void)
{
    long long int config = 5;
    gchar *t1 = "SERVER_PREFS";
    gchar *t2 = "NOT LIKE '%[%]%'";
    
    /**
        simale test
    **/
    //test_glib("%llu, %s, %s, %llu\n", config, t1, t2, config);
    test_vasprintf("%llu, %s, %s, %llu\n", config, t1, t2, config);
    
    /*
        origin sql code
        results are different on alpine linux and centos
    */
    const char *format = "SELECT config_preferences.name, config_preferences.value"
         " FROM config_preferences, nvt_preferences"
         " WHERE config_preferences.config = %llu"
         " AND config_preferences.type = '%s'"
         " AND (config_preferences.name = nvt_preferences.name"
         "      OR config_preferences.name LIKE 'timeout.%')"
         " AND config_preferences.name != 'max_checks'"
         " AND config_preferences.name != 'max_hosts'"            
         " UNION"                                                       
         " SELECT nvt_preferences.name, nvt_preferences.value"
         " FROM nvt_preferences"
         " WHERE nvt_preferences.name %s"
         " AND (SELECT COUNT(*) FROM config_preferences"
         "      WHERE config = %llu"
         "      AND config_preferences.name = nvt_preferences.name) = 0;\n\n";
    
    //test_glib(format, config, t1, t2, config);
    
    test_vasprintf(format, config, t1, t2, config); // It' ok on centos result, But it turns out to be null on alpine linux
    
    /*
        change 'timeout.%' to 'timeout.%%'
    */
    
    const char *format1 = "SELECT config_preferences.name, config_preferences.value"
         " FROM config_preferences, nvt_preferences"
         " WHERE config_preferences.config = %llu"
         " AND config_preferences.type = '%s'"
         " AND (config_preferences.name = nvt_preferences.name"
         "      OR config_preferences.name LIKE 'timeout.%%')"
         " AND config_preferences.name != 'max_checks'"
         " AND config_preferences.name != 'max_hosts'"            
         " UNION"                                                       
         " SELECT nvt_preferences.name, nvt_preferences.value"
         " FROM nvt_preferences"
         " WHERE nvt_preferences.name %s"
         " AND (SELECT COUNT(*) FROM config_preferences"
         "      WHERE config = %llu"
         "      AND config_preferences.name = nvt_preferences.name) = 0;\n\n";
    //test_glib(format1, config, t1, t2, config);
    
    test_vasprintf(format1, config, t1, t2, config);// same result, on centos and alpine linux
    
}

@b40yd b40yd requested a review from a team September 27, 2019 08:48
@bjoernricks bjoernricks added the bug Something isn't working label Sep 27, 2019
Copy link
Contributor

@mattmundell mattmundell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

Copy link
Contributor

@mattmundell mattmundell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we should note the fix in the changelog.

@mattmundell mattmundell merged commit 9471c26 into greenbone:gvmd-8.0 Sep 27, 2019
algitbot pushed a commit to alpinelinux/aports that referenced this pull request Sep 30, 2019
Merging the patch for the bug described in: greenbone/gvmd#473
and patched in greenbone/gvmd#758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants