Openembedded Core Discussions
 help / color / mirror / Atom feed
* [meta-oe][sumo][PATCH] systemd: fix codesonar warnings
@ 2020-08-07 14:31 Amitanand N Chikorde
  2020-08-07 14:48 ` [OE-core] " Quentin Schulz
  2020-08-07 15:02 ` ✗ patchtest: failure for systemd: Fix codesonar warnings (rev4) Patchwork
  0 siblings, 2 replies; 3+ messages in thread
From: Amitanand N Chikorde @ 2020-08-07 14:31 UTC (permalink / raw)
  To: openembedded-core, raj.khem
  Cc: nisha.parrakat, anuj.chougule, amitanand.chikorde

Fixed below systemd codesonar warnings.
1. isprint() and isspace() is invoked here with an argument of signed
type char, but only has defined behavior for int arguments that are
either representable as unsigned char or equal to the value
of macro EOF(-1).

As per codesonar report, in a number of libc implementations, isprint()
and isspace() functions implemented using lookup tables (arrays):
passing in a negative value can result in a read underrun.

To avoid this unexpected behaviour, typecasted char type argument to
unsigned char type.

2. "seqnum" defined, not initialized & used in device-private.c
Intialized "seqnum" at definition.

Signed-off-by: Amitanand <Amitanand.Chikorde@kpit.com>
---
 .../systemd/systemd_codesonar_warnings_fix.patch   | 105 +++++++++++++++++++++
 meta/recipes-core/systemd/systemd_245.6.bb         |   1 +
 2 files changed, 106 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/systemd_codesonar_warnings_fix.patch

diff --git a/meta/recipes-core/systemd/systemd/systemd_codesonar_warnings_fix.patch b/meta/recipes-core/systemd/systemd/systemd_codesonar_warnings_fix.patch
new file mode 100644
index 0000000..a62f968
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/systemd_codesonar_warnings_fix.patch
@@ -0,0 +1,105 @@
+systemd: fix codesonar warnings
+
+Fixed below systemd codesonar warnings.
+1. isprint() and isspace() is invoked here with an argument of signed
+type char, but only has defined behavior for int arguments that are
+either representable as unsigned char or equal to the value
+of macro EOF(-1).
+
+As per codesonar report, in a number of libc implementations, isprint()
+and isspace() functions implemented using lookup tables (arrays):
+passing in a negative value can result in a read underrun.
+
+To avoid this unexpected behaviour, typecasted char type argument to
+unsigned char type.
+
+2. "seqnum" defined, not initialized & used in device-private.c
+Intialized "seqnum" at definition.
+
+Upstream-Status: Pending
+Signed-off-by: Amitanand N. Chikorde <Amitanand.Chikorde@kpit.com>
+
+--- origcode/src/libsystemd/sd-device/device-private.c 2020-07-09 18:05:13.744127907 +0530
++++ modifcode/src/libsystemd/sd-device/device-private.c        2020-07-09 18:01:56.494621945 +0530
+@@ -560,7 +560,7 @@
+         char **key;
+         const char *major = NULL, *minor = NULL;
+         DeviceAction action = _DEVICE_ACTION_INVALID;
+-        uint64_t seqnum;
++        uint64_t seqnum = 0;
+         int r;
+
+         assert(ret);
+--- origcode/src/libudev/libudev-util.c        2020-07-09 18:05:13.656049515 +0530
++++ modifcode/src/libudev/libudev-util.c       2020-07-09 18:02:32.563386414 +0530
+@@ -171,7 +171,7 @@
+
+         /* strip trailing whitespace */
+         len = strnlen(str, len);
+-        while (len && isspace(str[len-1]))
++        while (len && isspace((unsigned char) str[len-1]))
+                 len--;
+
+         /* strip leading whitespace */
+@@ -182,8 +182,8 @@
+         j = 0;
+         while (i < len) {
+                 /* substitute multiple whitespace with a single '_' */
+-                if (isspace(str[i])) {
+-                        while (isspace(str[i]))
++                if (isspace((unsigned char) str[i])) {
++                        while (isspace((unsigned char) str[i]))
+                                 i++;
+                         to[j++] = '_';
+                 }
+--- origcode/src/udev/udevadm-hwdb.c   2020-07-09 18:05:13.612010318 +0530
++++ modifcode/src/udev/udevadm-hwdb.c  2020-07-09 18:03:26.243530163 +0530
+@@ -487,7 +487,7 @@
+
+                 /* strip trailing whitespace */
+                 len = strlen(line);
+-                while (len > 0 && isspace(line[len-1]))
++                while (len > 0 && isspace((unsigned char) line[len-1]))
+                         len--;
+                 line[len] = '\0';
+
+--- origcode/src/udev/udevadm-info.c   2020-07-09 18:05:13.616013882 +0530
++++ modifcode/src/udev/udevadm-info.c  2020-07-09 18:03:41.621625782 +0530
+@@ -73,7 +73,7 @@
+
+                 /* skip nonprintable attributes */
+                 len = strlen(value);
+-                while (len > 0 && isprint(value[len-1]))
++                while (len > 0 && isprint((unsigned char) value[len-1]))
+                         len--;
+                 if (len > 0)
+                         continue;
+--- origcode/src/udev/udev-rules.c     2020-07-09 18:05:13.624021008 +0530
++++ modifcode/src/udev/udev-rules.c    2020-07-09 18:03:03.227995790 +0530
+@@ -726,7 +726,7 @@
+                 return -1;
+
+         /* skip whitespace */
+-        while (isspace(linepos[0]) || linepos[0] == ',')
++        while (isspace((unsigned char) linepos[0]) || linepos[0] == ',')
+                 linepos++;
+
+         /* get the key */
+@@ -738,7 +738,7 @@
+                 linepos++;
+                 if (linepos[0] == '\0')
+                         return -1;
+-                if (isspace(linepos[0]))
++                if (isspace((unsigned char) linepos[0]))
+                         break;
+                 if (linepos[0] == '=')
+                         break;
+@@ -751,7 +751,7 @@
+         temp = linepos;
+
+         /* skip whitespace after key */
+-        while (isspace(linepos[0]))
++        while (isspace((unsigned char) linepos[0]))
+                 linepos++;
+         if (linepos[0] == '\0')
+                 return -1;
diff --git a/meta/recipes-core/systemd/systemd_245.6.bb b/meta/recipes-core/systemd/systemd_245.6.bb
index cdafb98..63c58e1 100644
--- a/meta/recipes-core/systemd/systemd_245.6.bb
+++ b/meta/recipes-core/systemd/systemd_245.6.bb
@@ -21,6 +21,7 @@ SRC_URI += "file://touchscreen.rules \
            file://0001-binfmt-Don-t-install-dependency-links-at-install-tim.patch \
            file://0003-implment-systemd-sysv-install-for-OE.patch \
            file://CVE-2020-13776.patch \
+           file://systemd_codesonar_warnings_fix.patch \
            "

 # patches needed by musl
--
2.7.4

This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-07 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-07 14:31 [meta-oe][sumo][PATCH] systemd: fix codesonar warnings Amitanand N Chikorde
2020-08-07 14:48 ` [OE-core] " Quentin Schulz
2020-08-07 15:02 ` ✗ patchtest: failure for systemd: Fix codesonar warnings (rev4) Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox