From b02689ab44e97028b113b2dd0d656249338c6413 Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:12:53 +0000 Subject: [PATCH] Remove g_time1() call This is not year 2038 compliant on systems with 32-bit integers. The call can be replaced with the standard C time() call. On POSIX systems, time_t is guaranteed to be an integer type. --- common/os_calls.c | 29 ----------------------------- common/os_calls.h | 1 - sesman/chansrv/clipboard_file.c | 2 +- sesman/libsesman/verify_user.c | 6 +++--- sesman/sesexec/login_info.c | 4 ++-- sesman/sesexec/session.c | 4 ++-- 6 files changed, 8 insertions(+), 38 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index afd5a958..d81cf0f1 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -2045,18 +2045,6 @@ g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs, int wcount, void g_random(char *data, int len) { -#if defined(_WIN32) - int index; - - srand(g_time1()); - - for (index = 0; index < len; index++) - { - data[index] = (char)rand(); /* rand returns a number between 0 and - RAND_MAX */ - } - -#else int fd; memset(data, 0x44, len); @@ -2075,8 +2063,6 @@ g_random(char *data, int len) close(fd); } - -#endif } /*****************************************************************************/ @@ -3777,21 +3763,6 @@ g_check_user_in_group(const char *username, int gid, int *ok) } #endif // HAVE_GETGROUPLIST -/*****************************************************************************/ -/* returns the time since the Epoch (00:00:00 UTC, January 1, 1970), - measured in seconds. - for windows, returns the number of seconds since the machine was - started. */ -int -g_time1(void) -{ -#if defined(_WIN32) - return GetTickCount() / 1000; -#else - return time(0); -#endif -} - /*****************************************************************************/ /* returns the number of milliseconds since the machine was started. */ diff --git a/common/os_calls.h b/common/os_calls.h index be06b07b..8de07bf3 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -393,7 +393,6 @@ int g_getgroup_info(const char *groupname, int *gid); * Primary group of username is also checked */ int g_check_user_in_group(const char *username, int gid, int *ok); -int g_time1(void); int g_time2(void); int g_time3(void); int g_save_to_bmp(const char *filename, char *data, int stride_bytes, diff --git a/sesman/chansrv/clipboard_file.c b/sesman/chansrv/clipboard_file.c index 90fed048..0be2f6e6 100644 --- a/sesman/chansrv/clipboard_file.c +++ b/sesman/chansrv/clipboard_file.c @@ -274,7 +274,7 @@ clipboard_get_file(const char *file, int bytes) list_add_item(g_files_list, (tintptr)cfi); cfi->size = g_file_get_size(full_fn); cfi->flags = CB_FILE_ATTRIBUTE_ARCHIVE; - cfi->time = (g_time1() + CB_EPOCH_DIFF) * 10000000LL; + cfi->time = (time(NULL) + CB_EPOCH_DIFF) * 10000000LL; LOG_DEVEL(LOG_LEVEL_DEBUG, "ok filename [%s] pathname [%s] size [%d]", cfi->filename, cfi->pathname, cfi->size); result = 0; diff --git a/sesman/libsesman/verify_user.c b/sesman/libsesman/verify_user.c index ccd289d2..fad83b42 100644 --- a/sesman/libsesman/verify_user.c +++ b/sesman/libsesman/verify_user.c @@ -225,7 +225,7 @@ auth_check_pwd_chg(const char *user) } /* check if we need a pwd change */ - now = g_time1(); + now = time(NULL); today = now / SECS_PER_DAY; if (stp->sp_expire == -1) @@ -306,7 +306,7 @@ auth_change_pwd(const char *user, const char *newpwd) } stp->sp_pwdp = g_strdup(hash); - today = g_time1() / SECS_PER_DAY; + today = time(NULL) / SECS_PER_DAY; stp->sp_lstchg = today; stp->sp_expire = today + stp->sp_max + stp->sp_inact; fd = fopen("/etc/shadow", "rw"); @@ -377,7 +377,7 @@ auth_account_disabled(struct spwd *stp) return 1; } - today = g_time1() / SECS_PER_DAY; + today = time(NULL) / SECS_PER_DAY; LOG_DEVEL(LOG_LEVEL_DEBUG, "last %ld", stp->sp_lstchg); LOG_DEVEL(LOG_LEVEL_DEBUG, "min %ld", stp->sp_min); diff --git a/sesman/sesexec/login_info.c b/sesman/sesexec/login_info.c index adb8ef1a..bb9d3f9e 100644 --- a/sesman/sesexec/login_info.c +++ b/sesman/sesexec/login_info.c @@ -57,8 +57,8 @@ log_authfail_message(const char *username, const char *ip_addr) { ip_addr = "unknown"; } - LOG(LOG_LEVEL_INFO, "AUTHFAIL: user=%s ip=%s time=%d", - username, ip_addr, g_time1()); + LOG(LOG_LEVEL_INFO, "AUTHFAIL: user=%s ip=%s time=%ld", + username, ip_addr, (long)time(NULL)); } /******************************************************************************/ diff --git a/sesman/sesexec/session.c b/sesman/sesexec/session.c index 11ec979d..13ac7f35 100644 --- a/sesman/sesexec/session.c +++ b/sesman/sesexec/session.c @@ -674,7 +674,7 @@ session_start_wrapped(struct login_info *login_info, sd->win_mgr = window_manager_pid; sd->x_server = display_pid; sd->chansrv = chansrv_pid; - sd->start_time = g_time1(); + sd->start_time = time(NULL); status = E_SCP_SCREATE_OK; } } @@ -860,7 +860,7 @@ session_process_child_exit(struct session_data *sd, } else if (pid == sd->win_mgr) { - int wm_wait_time = g_time1() - sd->start_time; + int wm_wait_time = time(NULL) - sd->start_time; if (e->reason == E_PXR_STATUS_CODE && e->val == 0) {