• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 25066591666

28 Apr 2026 05:01PM UTC coverage: 56.646%. First build
25066591666

Pull #2106

github

web-flow
Merge b71b13f22 into a8e505936
Pull Request #2106: Vs security fix

23 of 60 new or added lines in 4 files covered. (38.33%)

12858 of 22699 relevant lines covered (56.65%)

299321.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.73
/trick_source/sim_services/VariableServer/VariableServerSessionThread_loop.cpp
1

2
#include <iostream>
3
#ifdef __linux__
4
#include <cxxabi.h>
5
#endif
6

7
#include "trick/VariableServer.hh"
8
#include "trick/message_proto.h"
9
#include "trick/realtimesync_proto.h"
10
#include "trick/ExecutiveException.hh"
11
#include "trick/exec_proto.h"
12

13
#include "trick/VariableServerSessionThread.hh"
14

15
extern Trick::VariableServer * the_vs ;
16

17
void exit_var_thread(void *in_vst) ;
18

19
void * Trick::VariableServerSessionThread::thread_body() {
8✔
20

21
    // Check for short running sims
22
    test_shutdown(NULL, NULL);
8✔
23

24
    //  We need to make the thread to VariableServerSessionThread map before we accept the connection.
25
    //  Otherwise we have a race where this thread is unknown to the variable server and the
26
    //  client gets confirmation that the connection is ready for communication.
27
    _vs->add_vst( pthread_self() , this ) ;
8✔
28

29
    // Accept client connection
30
    int status = _connection->start();
8✔
31

32
    std::string new_ip = _connection->getClientHostname() ;
16✔
33
    //check against white list
34
    //skip this check if connection failed, don't want an erroneous error
35
    if (!_vs->get_bypass_ip_check() && status != CONNECTION_FAIL) {
8✔
NEW
36
        const std::set<std::string>& ips = _vs->get_ip_whitelist() ;
×
NEW
37
        bool valid_ip = false ;
×
NEW
38
        for (std::set<std::string>::iterator it = ips.begin(); it != ips.end(); ++it) {
×
NEW
39
            if ( new_ip.rfind(*it, 0) == 0 ) {
×
NEW
40
                valid_ip = true;
×
NEW
41
                break ;
×
42
            }
43
        }
44

NEW
45
        if ( !valid_ip ) {
×
NEW
46
            std::string err_msg = "ILLEGAL IP CONNECTION ATTEMPTED: " + new_ip + "\n";
×
NEW
47
            perror(err_msg.c_str()) ;
×
NEW
48
            status = CONNECTION_FAIL ;
×
49
        }
50
    }
51

52
    if (status != 0) {
8✔
53
        _vs->delete_vst(pthread_self());
1✔
54

55
        // Tell main thread that we failed to initialize
56
        pthread_mutex_lock(&_connection_status_mutex);
1✔
57
        _connection_status = CONNECTION_FAIL;
1✔
58
        pthread_cond_signal(&_connection_status_cv);
1✔
59
        pthread_mutex_unlock(&_connection_status_mutex);
1✔
60

61
        thread_shutdown();
1✔
62
    }
63

64
    // if log is set on for variable server (e.g., in input file), turn log on for each client
65
    if (_vs->get_log()) {
7✔
66
        _session->set_log(true);
×
67
    }
68

69
    if (_vs->get_session_log()) {
7✔
70
        _session->set_session_log(true);
×
71
    }
72

73
    if (_vs->get_info_msg()) {
7✔
74
        _session->set_info_message(true);
×
75
    }
76

77
    // Give the initialized connection to the session
78
    // Don't touch the connection anymore until we shut them both down
79
    _session->set_connection(_connection);
7✔
80
    _vs->add_session( pthread_self(), _session );
7✔
81

82
    // Tell main that we are ready
83
    pthread_mutex_lock(&_connection_status_mutex);
7✔
84
    _connection_status = CONNECTION_SUCCESS;
7✔
85
    pthread_cond_signal(&_connection_status_cv);
7✔
86
    pthread_mutex_unlock(&_connection_status_mutex);
7✔
87

88
    try {
89
        while (1) {
90
            // Shutdown here if it's time
91
            test_shutdown(exit_var_thread, (void *) this);
16✔
92

93
            // Pause here if we are in a restart condition
94
            test_pause();
14✔
95

96
            // Look for a message from the client
97
            // Parse and execute if one is availible
98
            int read_status = _session->handle_message();
14✔
99
            if ( read_status < 0 ) {
14✔
100
                break ;
1✔
101
            }
102

103
            // Check to see if exit is necessary
104
            if (_session->get_exit_cmd() == true) {
13✔
105
                break;
4✔
106
            }
107

108
            // Tell session it's time to copy and write if the mode is correct
109
            int ret =_session->copy_and_write_async(); 
9✔
110
            if (ret < 0) {
9✔
111
                break;
×
112
            }
113

114
            // Sleep for the appropriate cycle time
115
            usleep((unsigned int) (_session->get_update_rate() * 1000000));
9✔
116
        }
9✔
117
    } catch (Trick::ExecutiveException & ex ) {
×
118
        message_publish(MSG_ERROR, "\nVARIABLE SERVER COMMANDED exec_terminate\n  ROUTINE: %s\n  DIAGNOSTIC: %s\n" ,
×
119
         ex.file.c_str(), ex.message.c_str()) ;
120

121
        exec_signal_terminate();
×
122

123
    } catch (const std::exception &ex) {
×
124
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught std::exception\n  DIAGNOSTIC: %s\n" ,
×
125
         ex.what()) ;
×
126
        
127
        exec_signal_terminate();
×
128

129
#ifdef __linux__
130
#ifdef __GNUC__
131
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 2
132
    // for post gcc 4.1.2 or whatever glibc version is used in RHEL6 and above.
133
    } catch (abi::__forced_unwind&) {
4✔
134
        //pthread_exit and pthread_cancel will cause an abi::__forced_unwind to be thrown. Rethrow it.
135
        throw;
2✔
136
#endif
137
#endif
138
#endif
139
    } catch (...) {
×
140
#ifdef __linux__
141
#ifdef __GNUC__
142
#if (__GNUC__ == 4 && __GNUC_MINOR__ == 1) || __GNUC__ == 12
143
        // for gcc 4.1.2 or whatever glib version in RHEL 5 that does not work with the abi::__forced_unwind
144
        // Also seems to have a problem with gcc 12
145
        throw;
146
#else
147
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught unknown exception\n" ) ;
×
148
        exec_signal_terminate();
×
149
#endif
150
#endif
151
#endif
152
    }
153

154
    if (_debug >= 3) {
5✔
155
        message_publish(MSG_DEBUG, "%p tag=<%s> var_server receive loop exiting\n", _connection, _connection->getClientTag().c_str());
×
156
    }
157

158
    thread_shutdown(exit_var_thread, this);
5✔
159
    // No return from this.
160
}
×
161

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc