Skip to content

Commit b2d12da

Browse files
committed
NFS: Fix a MemorySanitizer error
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 b5353b6.
1 parent 766c227 commit b2d12da

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

parsenfsfh.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#include <stdio.h>
5050
#include <string.h>
51+
#include <limits.h>
5152

5253
#include "netdissect-ctype.h"
5354

@@ -389,18 +390,20 @@ Parse_fh(netdissect_options *ndo, const unsigned char *fh, u_int len,
389390
(void)fprintf(stderr, "\n");
390391
#endif
391392
/* Save the actual handle, so it can be display with -u */
393+
/* XXX really ? When -u is used this function is not called */
392394
for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++)
393395
(void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X",
394396
GET_U_1(fhp + i));
395397
fsidp->Opaque_Handle[i*2] = '\0';
396398

397399
/* XXX for now, give "bogus" values to aid debugging */
398400
fsidp->fsid_code = 0;
399-
fsidp->Fsid_dev.Minor = 257;
400-
fsidp->Fsid_dev.Major = 257;
401+
fsidp->Fsid_dev.Minor = UINT_MAX;
402+
fsidp->Fsid_dev.Major = UINT_MAX;
401403
*inop = 1;
402404

403-
/* display will show this string instead of (257,257) */
405+
/* display will show this string instead of (UINT_MAX,UINT_MAX) */
406+
/* XXX really ? */
404407
if (fsnamep)
405408
*fsnamep = "Unknown";
406409

print-nfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ nfs_printfh(netdissect_options *ndo,
904904
fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
905905
}
906906

907-
if(fsid.Fsid_dev.Minor == 257)
907+
if(fsid.Fsid_dev.Minor == UINT_MAX && fsid.Fsid_dev.Major == UINT_MAX)
908908
/* Print the undecoded handle */
909909
fn_print_str(ndo, (const u_char *)fsid.Opaque_Handle);
910910
else

0 commit comments

Comments
 (0)