SCP: Avoid potential buffer overflow using sprintf
- avoid warnings about snprintf truncation As reported in #717
This commit is contained in:
parent
eadfeffdf3
commit
9e71982249
2 changed files with 11 additions and 7 deletions
3
makefile
3
makefile
|
@ -1175,6 +1175,9 @@ ifneq (3,$(GCC_MAJOR_VERSION))
|
|||
ifneq (,$(findstring -Wunused-result,$(shell $(GCC_WARNINGS_CMD))))
|
||||
CFLAGS_O += -Wno-unused-result
|
||||
endif
|
||||
ifneq (,$(findstring -Wformat-truncation,$(shell $(GCC_WARNINGS_CMD))))
|
||||
CFLAGS_O += -Wno-format-truncation
|
||||
endif
|
||||
endif
|
||||
ifneq (clean,$(MAKECMDGOALS))
|
||||
BUILD_FEATURES := $(BUILD_FEATURES). $(COMPILER_NAME)
|
||||
|
|
15
sim_tmxr.c
15
sim_tmxr.c
|
@ -1005,6 +1005,7 @@ char *address;
|
|||
char msg[512];
|
||||
uint32 poll_time = sim_os_msec ();
|
||||
|
||||
memset (msg, 0, sizeof (msg));
|
||||
if (mp->last_poll_time == 0) { /* first poll initializations */
|
||||
UNIT *uptr = mp->uptr;
|
||||
|
||||
|
@ -1063,7 +1064,7 @@ if (mp->master) {
|
|||
newsock = sim_accept_conn_ex (mp->master, &address, (mp->packet ? SIM_SOCK_OPT_NODELAY : 0));/* poll connect */
|
||||
|
||||
if (newsock != INVALID_SOCKET) { /* got a live one? */
|
||||
sprintf (msg, "tmxr_poll_conn() - Connection from %s", address);
|
||||
snprintf (msg, sizeof (msg) - 1, "tmxr_poll_conn() - Connection from %s", address);
|
||||
tmxr_debug_connect (mp, msg);
|
||||
op = mp->lnorder; /* get line connection order list pointer */
|
||||
i = mp->lines; /* play it safe in case lines == 0 */
|
||||
|
@ -1199,7 +1200,7 @@ for (i = 0; i < mp->lines; i++) { /* check each line in se
|
|||
strcpy (lp->ipad, lp->destination);
|
||||
lp->cnms = sim_os_msec ();
|
||||
sim_getnames_sock (lp->sock, &sockname, &peername);
|
||||
sprintf (msg, "tmxr_poll_conn() - Outgoing Line Connection to %s (%s->%s) established", lp->destination, sockname, peername);
|
||||
snprintf (msg, sizeof (msg) -1, "tmxr_poll_conn() - Outgoing Line Connection to %s (%s->%s) established", lp->destination, sockname, peername);
|
||||
tmxr_debug_connect_line (lp, msg);
|
||||
free (sockname);
|
||||
free (peername);
|
||||
|
@ -1211,7 +1212,7 @@ for (i = 0; i < mp->lines; i++) { /* check each line in se
|
|||
}
|
||||
return i;
|
||||
case -1: /* failed connection */
|
||||
sprintf (msg, "tmxr_poll_conn() - Outgoing Line Connection to %s failed", lp->destination);
|
||||
snprintf (msg, sizeof (msg) -1, "tmxr_poll_conn() - Outgoing Line Connection to %s failed", lp->destination);
|
||||
tmxr_debug_connect_line (lp, msg);
|
||||
tmxr_reset_ln (lp); /* retry */
|
||||
break;
|
||||
|
@ -1224,7 +1225,7 @@ for (i = 0; i < mp->lines; i++) { /* check each line in se
|
|||
char *sockname, *peername;
|
||||
|
||||
sim_getnames_sock (newsock, &sockname, &peername);
|
||||
sprintf (msg, "tmxr_poll_conn() - Incoming Line Connection from %s (%s->%s)", address, peername, sockname);
|
||||
snprintf (msg, sizeof (msg) -1, "tmxr_poll_conn() - Incoming Line Connection from %s (%s->%s)", address, peername, sockname);
|
||||
tmxr_debug_connect_line (lp, msg);
|
||||
free (sockname);
|
||||
free (peername);
|
||||
|
@ -1235,14 +1236,14 @@ for (i = 0; i < mp->lines; i++) { /* check each line in se
|
|||
|
||||
if (sim_parse_addr (lp->destination, host, sizeof(host), NULL, NULL, 0, NULL, address)) {
|
||||
tmxr_msg (newsock, "Rejecting connection from unexpected source\r\n");
|
||||
sprintf (msg, "tmxr_poll_conn() - Rejecting line connection from: %s, Expected: %s", address, host);
|
||||
snprintf (msg, sizeof (msg) -1, "tmxr_poll_conn() - Rejecting line connection from: %s, Expected: %s", address, host);
|
||||
tmxr_debug_connect_line (lp, msg);
|
||||
sim_close_sock (newsock);
|
||||
free (address);
|
||||
continue; /* Try for another connection */
|
||||
}
|
||||
if (lp->connecting) {
|
||||
sprintf (msg, "tmxr_poll_conn() - aborting outgoing line connection attempt to: %s", lp->destination);
|
||||
snprintf (msg, sizeof (msg) -1, "tmxr_poll_conn() - aborting outgoing line connection attempt to: %s", lp->destination);
|
||||
tmxr_debug_connect_line (lp, msg);
|
||||
sim_close_sock (lp->connecting); /* abort our as yet unconnnected socket */
|
||||
lp->connecting = 0;
|
||||
|
@ -1286,7 +1287,7 @@ for (i = 0; i < mp->lines; i++) { /* check each line in se
|
|||
|
||||
if (lp->destination && (!lp->sock) && (!lp->connecting) && (!lp->serport) &&
|
||||
(!lp->modem_control || (lp->modembits & TMXR_MDM_DTR))) {
|
||||
sprintf (msg, "tmxr_poll_conn() - establishing outgoing connection to: %s", lp->destination);
|
||||
snprintf (msg, sizeof (msg) - 1, "tmxr_poll_conn() - establishing outgoing connection to: %s", lp->destination);
|
||||
tmxr_debug_connect_line (lp, msg);
|
||||
lp->connecting = sim_connect_sock_ex (lp->datagram ? lp->port : NULL, lp->destination, "localhost", NULL, (lp->datagram ? SIM_SOCK_OPT_DATAGRAM : 0) | (lp->mp->packet ? SIM_SOCK_OPT_NODELAY : 0));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue