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

nasa / trick / 25441446766

06 May 2026 02:26PM UTC coverage: 56.7% (-0.1%) from 56.83%
25441446766

push

github

web-flow
Vs security fix (#2106)

* VS Security fixes

* reformatting and update to trick sims

* cleanup

* more cleanup

* docs

* Test fix

* added stuff

* More stuff

* test fix

* trick sims update

* trick sims update2

* Rename to allowlist

* Remove returns for allow, disable, allow_all functions

* Change various function returns to bool

* Added free for getaddrinfo.

* Revise Variable Server documentation for security updates

Updated documentation to clarify that the variable server is disabled by default for security reasons and must be enabled prior to initialization. Enhanced security warnings regarding the potential risks of enabling the variable server.

* Warning update and moving adding localhost to after connections are allowed

* Clarify variable server disabled by default for security

Update documentation to clarify variable server security changes.

* Update default allowed IPs in Variable-Server.md

Clarified the default allowed IPs for the variable server.

* Add session deletion in VariableServerSessionThread_test

Fixed memory management by deleting session in the destructor.

---------

Co-authored-by: Brendan Fattig <brendan.fattig@nasa.gov>
Co-authored-by: Hong Chen <hchen99@users.noreply.github.com>
Co-authored-by: Sean Harmeyer <117398532+sharmeye@users.noreply.github.com>
Co-authored-by: Sean Harmeyer <sean.g.harmeyer@nasa.gov>

51 of 102 new or added lines in 4 files covered. (50.0%)

24 existing lines in 6 files now uncovered.

12902 of 22755 relevant lines covered (56.7%)

301334.0 hits per line

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

63.79
/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 allowlist
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
        bool valid_ip = _vs->check_ip(new_ip);
×
37

NEW
38
        if ( !valid_ip ) {
×
NEW
39
            std::string err_msg = "ILLEGAL IP CONNECTION ATTEMPTED: " + new_ip + "\n";
×
NEW
40
            message_publish(MSG_ERROR, err_msg.c_str()) ;
×
NEW
41
            status = CONNECTION_FAIL ;
×
42
        }
43
    }
44

45
    if (status != 0) {
8✔
46
        _vs->delete_vst(pthread_self());
1✔
47

48
        // Tell main thread that we failed to initialize
49
        pthread_mutex_lock(&_connection_status_mutex);
1✔
50
        _connection_status = CONNECTION_FAIL;
1✔
51
        pthread_cond_signal(&_connection_status_cv);
1✔
52
        pthread_mutex_unlock(&_connection_status_mutex);
1✔
53

54
        thread_shutdown();
1✔
55
    }
56

57
    // if log is set on for variable server (e.g., in input file), turn log on for each client
58
    if (_vs->get_log()) {
7✔
UNCOV
59
        _session->set_log(true);
×
60
    }
61

62
    if (_vs->get_session_log()) {
7✔
63
        _session->set_session_log(true);
×
64
    }
65

66
    if (_vs->get_info_msg()) {
7✔
67
        _session->set_info_message(true);
×
68
    }
69

70
    // Give the initialized connection to the session
71
    // Don't touch the connection anymore until we shut them both down
72
    _session->set_connection(_connection);
7✔
73
    _vs->add_session( pthread_self(), _session );
7✔
74

75
    // Tell main that we are ready
76
    pthread_mutex_lock(&_connection_status_mutex);
7✔
77
    _connection_status = CONNECTION_SUCCESS;
7✔
78
    pthread_cond_signal(&_connection_status_cv);
7✔
79
    pthread_mutex_unlock(&_connection_status_mutex);
7✔
80

81
    try {
82
        while (1) {
83
            // Shutdown here if it's time
84
            test_shutdown(exit_var_thread, (void *) this);
16✔
85

86
            // Pause here if we are in a restart condition
87
            test_pause();
14✔
88

89
            // Look for a message from the client
90
            // Parse and execute if one is availible
91
            int read_status = _session->handle_message();
14✔
92
            if ( read_status < 0 ) {
14✔
93
                break ;
1✔
94
            }
95

96
            // Check to see if exit is necessary
97
            if (_session->get_exit_cmd() == true) {
13✔
98
                break;
4✔
99
            }
100

101
            // Tell session it's time to copy and write if the mode is correct
102
            int ret =_session->copy_and_write_async(); 
9✔
103
            if (ret < 0) {
9✔
104
                break;
×
105
            }
106

107
            // Sleep for the appropriate cycle time
108
            usleep((unsigned int) (_session->get_update_rate() * 1000000));
9✔
109
        }
9✔
UNCOV
110
    } catch (Trick::ExecutiveException & ex ) {
×
UNCOV
111
        message_publish(MSG_ERROR, "\nVARIABLE SERVER COMMANDED exec_terminate\n  ROUTINE: %s\n  DIAGNOSTIC: %s\n" ,
×
112
         ex.file.c_str(), ex.message.c_str()) ;
113

UNCOV
114
        exec_signal_terminate();
×
115

UNCOV
116
    } catch (const std::exception &ex) {
×
UNCOV
117
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught std::exception\n  DIAGNOSTIC: %s\n" ,
×
UNCOV
118
         ex.what()) ;
×
119
        
UNCOV
120
        exec_signal_terminate();
×
121

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

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

151
    thread_shutdown(exit_var_thread, this);
5✔
152
    // No return from this.
153
}
×
154

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