On Wed, Jul 25, 2018 at 08:03:57AM -0400, Hal Rosenstock wrote: > > The default string of opt-console is OSM_DEFAULT_CONSOLE, which equal > "off". It is safe to copy 32 bytes in âosm_console_initâ, when the > 'console' field was initialized with default value. But this minor fix > avoids potential no NUL-terminated strncpy. > > make[2]: Entering directory '/home/honli/upstream-repos/opensm/opensm' > depbase=`echo osm_console_io.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ > gcc -DHAVE_CONFIG_H -I. -I../include -I../include/opensm -I./../include -I./../../libibumad/include -I/usr/local/include -Werror -Wall -Wwrite-strings -g -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE=1 -g -O2 -MT osm_console_io.o -MD -MP -MF $depbase.Tpo -c -o osm_console_io.o osm_console_io.c &&\ > mv -f $depbase.Tpo $depbase.Po > osm_console_io.c: In function âosm_console_initâ: > osm_console_io.c:186:2: error: âstrncpyâ specified bound 32 equals destination size [-Werror=stringop-truncation] > strncpy(p_oct->client_type, opt->console, sizeof(p_oct->client_type)); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > cc1: all warnings being treated as errors > > Signed-off-by: Honggang Li <honli@xxxxxxxxxx> > Signed-off-by: Hal Rosenstock <hal@xxxxxxxxxxxx> > --- > opensm/osm_console_io.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/opensm/osm_console_io.c b/opensm/osm_console_io.c > index f529e25..97fe674 100644 > --- a/opensm/osm_console_io.c > +++ b/opensm/osm_console_io.c > @@ -182,7 +182,8 @@ void osm_console_prompt(FILE * out) > int osm_console_init(osm_subn_opt_t * opt, osm_console_t * p_oct, osm_log_t * p_log) > { > p_oct->socket = -1; > - strncpy(p_oct->client_type, opt->console, sizeof(p_oct->client_type)); > + strncpy(p_oct->client_type, opt->console, sizeof(p_oct->client_type) - 1); > + p_oct->client_type[sizeof(p_oct->client_type) - 1] = '\0'; > > /* set up the file descriptors for the console */ > if (strcmp(opt->console, OSM_LOCAL_CONSOLE) == 0) { Acked-by: Honggang Li <honli@xxxxxxxxxx> > -- > 2.8.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html