Skip to contentSkip to conversation

Tools: hv: fix file overwriting of hv_fcopy_daemon

PATCH In review Yue Zhang 2 participants 3 messages Jun 26, 2014 Hyper-V/Azure core and drivers

lore
Share & tools
lore

Yue Zhang

author
#0 lore raw

PATCH 1/1 Tools: hv: fix file overwriting of hv_fcopy_daemon

From: Yue Zhang <[email protected]>

hv_fcopy_daemon fails to overwrite a file if the target file already exits.

Add O_TRUNC flag on opening.

---
 tools/hv/hv_fcopy_daemon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/hv/hv_fcopy_daemon.c +2 -1
index fba1c75..01eee6b 100644
@@ -88,7 +88,8 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
 		}
 	}
 
-	target_fd = open(target_fname, O_RDWR | O_CREAT | O_CLOEXEC, 0744);
+	target_fd = open(target_fname,
+				O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0744);
 	if (target_fd == -1) {
 		syslog(LOG_INFO, "Open Failed: %s", strerror(errno));
 		goto done;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 27 lines

-----Original Message-----
From: Yue Zhang [mailto:[email protected]]
Sent: Thursday, June 26, 2014 2:09 PM
To: KY Srinivasan; Haiyang Zhang; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Dexuan Cui; Thomas Shao
Subject: [PATCH] Tools: hv: fix file overwriting of hv_fcopy_daemon

From: Yue Zhang <[email protected]>

hv_fcopy_daemon fails to overwrite a file if the target file already exits.

Add O_TRUNC flag on opening.

---
 tools/hv/hv_fcopy_daemon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/hv/hv_fcopy_daemon.c +0 -0
index fba1c75..01eee6b 100644

tools/hv/hv_fcopy_daemon.c static int hv_start_fcopy(struct hv_start_fcopy *smsg) · line 93

Quoted 7 lines
tools/hv/hv_fcopy_daemon.c +2 -1
@@ -88,7 +88,8 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
 		}
 	}
 
-	target_fd = open(target_fname, O_RDWR | O_CREAT | O_CLOEXEC,
 0744);
+	target_fd = open(target_fname,
+				O_RDWR | O_CREAT | O_TRUNC |

Please align O_RDWR to align with the first argument (target_fname).

K. Y

#2 lore raw
Quoted 22 lines

-----Original Message-----
From: KY Srinivasan

Quoted 18 lines

-----Original Message-----
From: Yue Zhang [mailto:[email protected]]
hv_fcopy_daemon fails to overwrite a file if the target file already exits.

Add O_TRUNC flag on opening.

---
 tools/hv/hv_fcopy_daemon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/hv/hv_fcopy_daemon.c +0 -0
index fba1c75..01eee6b 100644
@@ -88,7 +88,8 @@ static int hv_start_fcopy(struct hv_start_fcopy
 *smsg)  }  }
 
Quoted 4 lines

tools/hv/hv_fcopy_daemon.c static int hv_start_fcopy(struct hv_start_fcopy *smsg)

Quoted 3 lines
tools/hv/hv_fcopy_daemon.c +2 -1
-target_fd = open(target_fname, O_RDWR | O_CREAT | O_CLOEXEC, 0744);
+target_fd = open(target_fname,
+O_RDWR | O_CREAT | O_TRUNC |

Please align O_RDWR to align with the first argument (target_fname).

Thanks. I will fix it.

Quoted 3 lines

K. Y