Memory Sanitizer reports use of uninitialized stream/pstream pointers
while recording results of open/listen:

 WARNING: MemorySanitizer: use-of-uninitialized-value
  0 0x7c48cf in pstream_open lib/stream.c:567:5
  1 0x7c71ed in pstream_open_with_default_port lib/stream.c:772:13
  2 0x6c7731 in jsonrpc_pstream_open lib/jsonrpc.c:80:12
  3 0x509345 in ovsdb_jsonrpc_server_add_remote ovsdb/jsonrpc-server.c:374:13
  4 0x508eed in ovsdb_jsonrpc_server_set_remotes ovsdb/jsonrpc-server.c:355:22
  5 0x4dca59 in reconfigure_remotes ovsdb/ovsdb-server.c:1778:5
  6 0x4c9d42 in reconfigure_ovsdb_server ovsdb/ovsdb-server.c:686:19
  7 0x4c432a in main ovsdb/ovsdb-server.c:788:10
  8 0x7fb979 in __libc_start_call_main
  9 0x7fb979 in __libc_start_main@GLIBC_2.2.5
 10 0x432b64 in _start (ovsdb/ovsdb-server+0x432b64)

It complains just about the function call even if the value inside the
function is not being used.  Can be fixed by initializing the stream
pointer to NULL.  However, there is a possibility of it being used when
we also fail to record the result.  We should be using the provided
name in the error log instead of trying to access the name through the
potentially uninitialized or NULL pointer.

While at it, also fixing the log message to be more accurate.

Fixes: fae1ae0434cd ("stream: Add record/replay functionality.")
Signed-off-by: Ilya Maximets <[email protected]>
---
 lib/stream-replay.c | 6 +++---
 lib/stream.c        | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/stream-replay.c b/lib/stream-replay.c
index 21da5220e..eb552a529 100644
--- a/lib/stream-replay.c
+++ b/lib/stream-replay.c
@@ -114,8 +114,8 @@ stream_replay_open_wfd(struct stream *s, int open_result, 
const char *name)
     ovs_replay_unlock();
 
     if (ovs_replay_write(f, NULL, -open_result, true)) {
-        VLOG_ERR_RL(&rl, "%s: failed to write 'open' failure: %d",
-                    s->name, open_result);
+        VLOG_ERR_RL(&rl, "%s: failed to write 'open' result: %d",
+                    name, open_result);
     }
     if (open_result) {
         /* We recorded failure to open the stream. */
@@ -343,7 +343,7 @@ pstream_replay_open_wfd(struct pstream *ps, int 
listen_result,
 
     if (ovs_replay_write(f, NULL, -listen_result, true)) {
         VLOG_ERR_RL(&rl, "%s: failed to write 'listen' result: %d",
-                    ps->name, listen_result);
+                    name, listen_result);
     }
 
     if (listen_result) {
diff --git a/lib/stream.c b/lib/stream.c
index 71039e24f..6f5821689 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -216,7 +216,7 @@ int
 stream_open(const char *name, struct stream **streamp, uint8_t dscp)
 {
     const struct stream_class *class;
-    struct stream *stream;
+    struct stream *stream = NULL;
     char *suffix_copy;
     int error;
 
@@ -547,7 +547,7 @@ int
 pstream_open(const char *name, struct pstream **pstreamp, uint8_t dscp)
 {
     const struct pstream_class *class;
-    struct pstream *pstream;
+    struct pstream *pstream = NULL;
     char *suffix_copy;
     int error;
 
-- 
2.47.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to