Skip to content

Commit

Permalink
Remove g_time1() call
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matt335672 committed Dec 4, 2024
1 parent e404509 commit 267d5bd
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 38 deletions.
29 changes: 0 additions & 29 deletions common/os_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -2075,8 +2063,6 @@ g_random(char *data, int len)

close(fd);
}

#endif
}

/*****************************************************************************/
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 0 additions & 1 deletion common/os_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sesman/chansrv/clipboard_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions sesman/libsesman/verify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions sesman/sesexec/login_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/******************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions sesman/sesexec/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 267d5bd

Please sign in to comment.