]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NFS: Fix a MemorySanitizer error
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 5 Nov 2023 18:46:54 +0000 (19:46 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 6 Nov 2023 07:59:24 +0000 (08:59 +0100)
In parsenfsfh.c, Parse_fh(), switch (fhtype), case FHT_SUNOS5, the
Fsid_dev.Minor can be 257.

Thus using 257 as a flag value ("bogus") in case FHT_UNKNOWN when
Opaque_Handle[] is initialized is incorrect. This value is tested in
nfs_printfh() to print or not Opaque_Handle[]. This can result in a case
of use-of-uninitialized-value.

To avoid this, use UINT_MAX as flag values for Fsid_dev.Minor and
Fsid_dev.Major and test the two variables in nfs_printfh().

The error was:
==9391==WARNING: MemorySanitizer: use-of-uninitialized-value
[...]
MemorySanitizer: use-of-uninitialized-value util-print.c:91:2
in fn_print_str

Add two XXX comments with questions.

follow-up to commit deb442927d6ef04db19b07a015b9083f0ebde84b.

(cherry picked from commit b2d12dad707f6ac73eeb9cb70fa69449869b1ec1)

parsenfsfh.c
print-nfs.c

index 594177c1e02d2b79483b5b07f464e50972696549..a6186885f6731a7e400f06889fe389fd5a7f1337 100644 (file)
@@ -48,6 +48,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <limits.h>
 
 #include "netdissect-ctype.h"
 
@@ -389,6 +390,7 @@ Parse_fh(netdissect_options *ndo, const unsigned char *fh, u_int len,
            (void)fprintf(stderr, "\n");
 #endif
            /* Save the actual handle, so it can be display with -u */
+           /* XXX really ? When -u is used this function is not called */
            for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++)
                (void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X",
                               GET_U_1(fhp + i));
@@ -396,11 +398,12 @@ Parse_fh(netdissect_options *ndo, const unsigned char *fh, u_int len,
 
            /* XXX for now, give "bogus" values to aid debugging */
            fsidp->fsid_code = 0;
-           fsidp->Fsid_dev.Minor = 257;
-           fsidp->Fsid_dev.Major = 257;
+           fsidp->Fsid_dev.Minor = UINT_MAX;
+           fsidp->Fsid_dev.Major = UINT_MAX;
            *inop = 1;
 
-           /* display will show this string instead of (257,257) */
+           /* display will show this string instead of (UINT_MAX,UINT_MAX) */
+           /* XXX really ? */
            if (fsnamep)
                *fsnamep = "Unknown";
 
index 8d403a20c9b639bc65e5bbf8e73ad97d762360c8..bbce49536f2acf653179c742e85bccc4d324c534 100644 (file)
@@ -904,7 +904,7 @@ nfs_printfh(netdissect_options *ndo,
                             fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
        }
 
-       if(fsid.Fsid_dev.Minor == 257)
+       if(fsid.Fsid_dev.Minor == UINT_MAX && fsid.Fsid_dev.Major == UINT_MAX)
                /* Print the undecoded handle */
                fn_print_str(ndo, (const u_char *)fsid.Opaque_Handle);
        else