From b31cc6ecd93e453834a29a65106b4518229d4081 Mon Sep 17 00:00:00 2001 From: Nate Bargmann Date: Sat, 7 Jan 2012 20:50:34 -0600 Subject: [PATCH] Assure NULL terminated strings in src files. Various strncpy operations could result in a port pathname that is not a NULL terminated string as the allowed string length is the same size as the buffer per the strncpy manual page. This is corrected by assuring that the allowed length is FILPATHLEN - 1. --- src/rig.c | 8 ++++---- src/rotator.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rig.c b/src/rig.c index 651ef516a..65d6427a1 100644 --- a/src/rig.c +++ b/src/rig.c @@ -292,7 +292,7 @@ RIG * HAMLIB_API rig_init(rig_model_t rig_model) switch (caps->port_type) { case RIG_PORT_SERIAL: - strncpy(rs->rigport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN); + strncpy(rs->rigport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1); rs->rigport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */ rs->rigport.parm.serial.data_bits = caps->serial_data_bits; rs->rigport.parm.serial.stop_bits = caps->serial_stop_bits; @@ -301,16 +301,16 @@ RIG * HAMLIB_API rig_init(rig_model_t rig_model) break; case RIG_PORT_PARALLEL: - strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN); + strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN - 1); break; case RIG_PORT_NETWORK: case RIG_PORT_UDP_NETWORK: - strncpy(rs->rigport.pathname, "127.0.0.1:4532", FILPATHLEN); + strncpy(rs->rigport.pathname, "127.0.0.1:4532", FILPATHLEN - 1); break; default: - strncpy(rs->rigport.pathname, "", FILPATHLEN); + strncpy(rs->rigport.pathname, "", FILPATHLEN - 1); } rs->rigport.write_delay = caps->write_delay; diff --git a/src/rotator.c b/src/rotator.c index de9bf9979..a74986b19 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -223,7 +223,7 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model) switch (caps->port_type) { case RIG_PORT_SERIAL: - strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN); + strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1); rs->rotport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */ rs->rotport.parm.serial.data_bits = caps->serial_data_bits; rs->rotport.parm.serial.stop_bits = caps->serial_stop_bits; @@ -232,16 +232,16 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model) break; case RIG_PORT_PARALLEL: - strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN); + strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN - 1); break; case RIG_PORT_NETWORK: case RIG_PORT_UDP_NETWORK: - strncpy(rs->rotport.pathname, "127.0.0.1:4533", FILPATHLEN); + strncpy(rs->rotport.pathname, "127.0.0.1:4533", FILPATHLEN - 1); break; default: - strncpy(rs->rotport.pathname, "", FILPATHLEN); + strncpy(rs->rotport.pathname, "", FILPATHLEN - 1); } rs->min_el = caps->min_el;