mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-07 13:20:02 +02:00
Protect from getenv("HOME") returning nullptr (#907)
* Protect from getenv("HOME") returning nullptr (e.g., in case running in systemd) * Write proper warning in Module.cpp
This commit is contained in:
parent
aa173d3a87
commit
6251dc1b71
@ -3332,7 +3332,13 @@ void Module::initializeModuleStructure(detectorType type) {
|
|||||||
shm()->numberOfModule.y = 0;
|
shm()->numberOfModule.y = 0;
|
||||||
shm()->controlPort = DEFAULT_TCP_CNTRL_PORTNO;
|
shm()->controlPort = DEFAULT_TCP_CNTRL_PORTNO;
|
||||||
shm()->stopPort = DEFAULT_TCP_STOP_PORTNO;
|
shm()->stopPort = DEFAULT_TCP_STOP_PORTNO;
|
||||||
strcpy_safe(shm()->settingsDir, getenv("HOME"));
|
char *home_directory = getenv("HOME");
|
||||||
|
if (home_directory != nullptr)
|
||||||
|
strcpy_safe(shm()->settingsDir, home_directory);
|
||||||
|
else {
|
||||||
|
strcpy_safe(shm()->settingsDir, "");
|
||||||
|
LOG(logWARNING) << "HOME directory not set";
|
||||||
|
}
|
||||||
strcpy_safe(shm()->rxHostname, "none");
|
strcpy_safe(shm()->rxHostname, "none");
|
||||||
shm()->rxTCPPort = DEFAULT_TCP_RX_PORTNO + moduleIndex;
|
shm()->rxTCPPort = DEFAULT_TCP_RX_PORTNO + moduleIndex;
|
||||||
shm()->useReceiverFlag = false;
|
shm()->useReceiverFlag = false;
|
||||||
|
@ -20,6 +20,7 @@ Still this is better than strcpy and a buffer overflow...
|
|||||||
*/
|
*/
|
||||||
template <size_t array_size>
|
template <size_t array_size>
|
||||||
void strcpy_safe(char (&destination)[array_size], const char *source) {
|
void strcpy_safe(char (&destination)[array_size], const char *source) {
|
||||||
|
assert(source != nullptr);
|
||||||
assert(array_size > strlen(source));
|
assert(array_size > strlen(source));
|
||||||
strncpy(destination, source, array_size - 1);
|
strncpy(destination, source, array_size - 1);
|
||||||
destination[array_size - 1] = '\0';
|
destination[array_size - 1] = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user