Skip to contentSkip to conversation

xfsprogs: 2 quick coverity fixes

PATCH In review Eric Sandeen 2 participants 5 messages Apr 14, 2014

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 xfs_logprint: Fix error handling in xlog_print_trans_efi

A recent change to xlog_print_trans_efi() led to a leaked "src_f" on this error return.

---

logprint/log_misc.c +3 -2
index 928f60a..d482cf3 100644
@@ -482,7 +482,7 @@ xlog_print_trans_efi(
 	uint src_len,
 	int continued)
 {
-    xfs_efi_log_format_t *src_f, *f;
+    xfs_efi_log_format_t *src_f, *f = NULL;
     uint		 dst_len;
     xfs_extent_t	 *ex;
     int			 i;
@@ -505,7 +505,8 @@ xlog_print_trans_efi(
 
     if (continued && src_len < core_size) {
 	printf(_("EFI: Not enough data to decode further\n"));
-	return 1;
+	error = 1;
+	goto error;
     }
 
     if ((f = (xfs_efi_log_format_t *)malloc(dst_len)) == NULL) {

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs_logprint: Fix error handling in xlog_print_trans_efi

Quoted 21 lines · Eric Sandeen

A recent change to xlog_print_trans_efi() led to a leaked "src_f" on this error return.

---

logprint/log_misc.c +1 -1
index 928f60a..d482cf3 100644
@@ -482,7 +482,7 @@ xlog_print_trans_efi(
  	uint src_len,
  	int continued)
  {
-    xfs_efi_log_format_t *src_f, *f;
+    xfs_efi_log_format_t *src_f, *f = NULL;
      uint		 dst_len;
      xfs_extent_t	 *ex;
      int			 i;

logprint/log_misc.c xlog_print_trans_efi( · line 512

Quoted 9 lines
logprint/log_misc.c +2 -1
@@ -505,7 +505,8 @@ xlog_print_trans_efi(
 
      if (continued&&  src_len<  core_size) {
  	printf(_("EFI: Not enough data to decode further\n"));
-	return 1;
+	error = 1;
+	goto error;
      }
 
      if ((f = (xfs_efi_log_format_t *)malloc(dst_len)) == NULL) {

Looks good. Thank-you Eric and Coverity.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

Re: [PATCH 2/2] mkfs.xfs: prevent close(-1) on protofile error path

In reply to Eric Sandeen

My previous cleanups introduced this; in the case where fd=open() failed, the out_fail: path would try to close(-1).

---

mkfs/proto.c +2 -1
index 308325b..5a47e27 100644
@@ -84,7 +84,8 @@ setup_proto(
 	return buf;
 
 out_fail:
-	close(fd);
+	if (fd >= 0)
+		close(fd);
 	free(buf);
 	exit(1);
 }

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by
#4 lore raw

Re: [PATCH 2/2] mkfs.xfs: prevent close(-1) on protofile error path

Quoted 12 lines · Eric Sandeen

My previous cleanups introduced this; in the case where fd=open() failed, the out_fail: path would try to close(-1).

---

mkfs/proto.c +0 -0
index 308325b..5a47e27 100644

mkfs/proto.c setup_proto( · line 91

Quoted 9 lines
mkfs/proto.c +2 -1
@@ -84,7 +84,8 @@ setup_proto(
  	return buf;
 
  out_fail:
-	close(fd);
+	if (fd>= 0)
+		close(fd);
  	free(buf);
  	exit(1);
  }

I would have bypassed the close with a new open error goto, but this does the trick as well.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs