[oe,meta-networking,5/5] ippool: Fix strncpy -Wformat-truncation warning

Message ID 20191227035639.303716-5-raj.khem@gmail.com
State Superseded
Headers show
Series
  • [oe,meta-multimedia,1/5] mpd: Fix build with gcc10
Related show

Commit Message

Khem Raj Dec. 27, 2019, 3:56 a.m.
Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 .../ippool/ippool/strncpy-truncation.patch    | 35 +++++++++++++++++++
 .../recipes-daemons/ippool/ippool_1.3.bb      |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644 meta-networking/recipes-daemons/ippool/ippool/strncpy-truncation.patch

-- 
2.24.1

-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

Comments

Adrian Bunk Dec. 27, 2019, 5:26 a.m. | #1
On Thu, Dec 26, 2019 at 07:56:39PM -0800, Khem Raj wrote:
>...

> +| ippool_config.c:112:2: note: 'snprintf' output between 8 and 55 bytes into a destination of size 48

> +|   112 |  snprintf(prompt, sizeof(prompt), "ippool-%s", server_name);

> +|       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> +

> +Upstream-Status: Pending

> +Signed-off-by: Khem Raj <raj.khem@gmail.com>

> +--- a/cli/cli_readline.c

> ++++ b/cli/cli_readline.c

>...


Is this a paste of the wrong warning?
The patch is in a different file in code that looks unrelated.

cu
Adrian
-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel
Adrian Bunk Dec. 27, 2019, 8:12 a.m. | #2
On Thu, Dec 26, 2019 at 07:56:39PM -0800, Khem Raj wrote:
>...

> +--- a/cli/cli_readline.c

> ++++ b/cli/cli_readline.c

> +@@ -261,6 +261,11 @@ static void cli_rl_display_wrapped_text(

> + 	if (left_margin == 0) {

> + 		left_margin = 3;

> + 	}

> ++

> ++	if (left_margin >= strlen(text_buf)) {

> ++		left_margin = strlen(text_buf);

> ++	}

>...


This doesn't make sense, text_buf is an uninitialized variable.

cu
Adrian
-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel
Khem Raj Dec. 27, 2019, 8:48 a.m. | #3
On Fri, Dec 27, 2019 at 12:12 AM Adrian Bunk <bunk@stusta.de> wrote:
>

> On Thu, Dec 26, 2019 at 07:56:39PM -0800, Khem Raj wrote:

> >...

> > +--- a/cli/cli_readline.c

> > ++++ b/cli/cli_readline.c

> > +@@ -261,6 +261,11 @@ static void cli_rl_display_wrapped_text(

> > +     if (left_margin == 0) {

> > +             left_margin = 3;

> > +     }

> > ++

> > ++    if (left_margin >= strlen(text_buf)) {

> > ++            left_margin = strlen(text_buf);

> > ++    }

> >...

>

> This doesn't make sense, text_buf is an uninitialized variable.

>


I had it replaced with 128 already, this patch can be ignored

> cu

> Adrian

-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

Patch

diff --git a/meta-networking/recipes-daemons/ippool/ippool/strncpy-truncation.patch b/meta-networking/recipes-daemons/ippool/ippool/strncpy-truncation.patch
new file mode 100644
index 0000000000..28cad001db
--- /dev/null
+++ b/meta-networking/recipes-daemons/ippool/ippool/strncpy-truncation.patch
@@ -0,0 +1,35 @@ 
+Replace strncpy with memcpy 
+
+since the length of data to 
+be copied has already been determined with strlen(). Replace strncpy()
+with memcpy() to address the warning and optimize the code a little.
+
+| ippool_config.c:112:2: note: 'snprintf' output between 8 and 55 bytes into a destination of size 48
+|   112 |  snprintf(prompt, sizeof(prompt), "ippool-%s", server_name);
+|       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+--- a/cli/cli_readline.c
++++ b/cli/cli_readline.c
+@@ -261,6 +261,11 @@ static void cli_rl_display_wrapped_text(
+ 	if (left_margin == 0) {
+ 		left_margin = 3;
+ 	}
++
++	if (left_margin >= strlen(text_buf)) {
++		left_margin = strlen(text_buf);
++	}
++
+ 	if (right_margin == 0) {
+ 		right_margin = 78;;
+ 	}
+@@ -271,7 +276,7 @@ static void cli_rl_display_wrapped_text(
+ 	/* First copy the text heading to the buffer and add a "-", accounting for
+ 	 * the specified left margin.
+ 	 */
+-	strncpy(&text_buf[0], text1, left_margin - 3);
++	memcpy(&text_buf[0], text1, left_margin - 3);
+ 	for (pos = strlen(text1); pos < left_margin - 3; pos++) {
+ 		text_buf[pos] = ' ';
+ 	}
diff --git a/meta-networking/recipes-daemons/ippool/ippool_1.3.bb b/meta-networking/recipes-daemons/ippool/ippool_1.3.bb
index 6fa46904b3..3554e688ab 100644
--- a/meta-networking/recipes-daemons/ippool/ippool_1.3.bb
+++ b/meta-networking/recipes-daemons/ippool/ippool_1.3.bb
@@ -26,6 +26,7 @@  SRC_URI = "https://sourceforge.net/projects/openl2tp/files/${BPN}/${PV}/${BPN}-$
            file://0003-cli-Mark-return-of-strtol-as-long-int.patch \
            file://0002-link-with-libtirpc.patch \
            file://0003-musl-fixes.patch \
+           file://strncpy-truncation.patch \
            "
 
 LIC_FILES_CHKSUM = "file://LICENSE;md5=4c59283b82fc2b166455e0fc23c71c6f"