From c29be795c254d3c0b83a042a30092abe65c0d925 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Sat, 24 Oct 2020 12:39:28 -0300 Subject: [PATCH] Fixing code scanning alerts. --- src/core/ctlr.c | 9 +++++++-- src/core/rpq.c | 23 +++++++++++++++-------- src/core/telnet.c | 9 ++++++--- src/core/util.c | 2 +- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/core/ctlr.c b/src/core/ctlr.c index 7868104..ed6ad6a 100644 --- a/src/core/ctlr.c +++ b/src/core/ctlr.c @@ -2364,8 +2364,13 @@ void ctlr_clear(H3270 *session, Boolean can_snap) #endif - /* Clear the screen. */ - (void) memset((char *)session->ea_buf, 0, session->view.rows * session->view.cols * sizeof(struct lib3270_ea)); + // Clear the screen. + (void) memset( + (char *)session->ea_buf, + 0, + ((size_t)session->view.rows) * ((size_t) session->view.cols) * sizeof(struct lib3270_ea) + ); + cursor_move(session,0); session->buffer_addr = 0; diff --git a/src/core/rpq.c b/src/core/rpq.c index 2a6fe6c..cf43b00 100644 --- a/src/core/rpq.c +++ b/src/core/rpq.c @@ -376,9 +376,7 @@ static Boolean select_rpq_terms(H3270 *hSession) return False; } -/** - * @brief Utility function used by the RPQNAMES query reply. - */ +/// @brief Utility function used by the RPQNAMES query reply. static int get_rpq_timezone(H3270 *hSession) { /* @@ -394,7 +392,7 @@ static int get_rpq_timezone(H3270 *hSession) */ time_t here; struct tm here_tm; - struct tm *utc_tm; + struct tm utc_tm; double delta; char *p1, *p2; struct rpq_keyword *kw; @@ -440,22 +438,31 @@ static int get_rpq_timezone(H3270 *hSession) } -// memcpy(&here_tm, localtime(&here), sizeof(struct tm)); - localtime_r(&here, &here_tm); + localtime_r(&here,&here_tm); + + if(gmtime_r(&here,&utc_tm) == NULL) + { + rpq_warning(hSession, _("RPQ: Unable to determine workstation UTC time")); + return 2; + } + + /* + memcpy(&here_tm, localtime(&here), sizeof(struct tm)); if ((utc_tm = gmtime(&here)) == NULL) { rpq_warning(hSession, _("RPQ: Unable to determine workstation UTC time")); return 2; } + */ /* * Do not take Daylight Saving Time into account. * We just want the "raw" time difference. */ here_tm.tm_isdst = 0; - utc_tm->tm_isdst = 0; - delta = difftime(mktime(&here_tm), mktime(utc_tm)) / 60L; + utc_tm.tm_isdst = 0; + delta = difftime(mktime(&here_tm), mktime(&utc_tm)) / 60L; } // sanity check: difference cannot exceed +/- 12 hours diff --git a/src/core/telnet.c b/src/core/telnet.c index d4d8806..5641aec 100644 --- a/src/core/telnet.c +++ b/src/core/telnet.c @@ -2152,10 +2152,13 @@ void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, in int offset; int col = 0; - time_t ltime; + { + time_t ltime; + struct tm tm; + time(<ime); + strftime(l1, 81, "%x %X", localtime_r(<ime,&tm)); + } - time(<ime); - strftime(l1, 81, "%x %X", localtime(<ime)); lib3270_write_nettrace(hSession,"%c %s %s data len=%d\n\n",direction,l1,direction == '>' ? "SEND" : "RECV", len); for (offset = 0; offset < len; offset++) diff --git a/src/core/util.c b/src/core/util.c index c5a3d7a..cb9bb12 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -183,7 +183,7 @@ LIB3270_EXPORT void * lib3270_realloc(void *p, int len) LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr) { - size_t sz = nelem * elsize; + size_t sz = ((size_t) nelem) * ((size_t) elsize); if(ptr) ptr = realloc(ptr,sz); -- libgit2 0.21.2