@@ -226,9 +226,10 @@ def run_command(cmd, target=false, stdinfile=false, env={})
226
226
227
227
# the java keytool will not correctly deal with an empty target keystore
228
228
# file. If we encounter an empty keystore target file, preserve the mode,
229
- # owner and group, and delete the empty file.
229
+ # owner and group, temporarily raise the umask, and delete the empty file.
230
230
if target and ( File . exists? ( target ) and File . zero? ( target ) )
231
231
stat = File . stat ( target )
232
+ umask = File . umask ( 0077 )
232
233
File . delete ( target )
233
234
end
234
235
@@ -259,12 +260,15 @@ def run_command(cmd, target=false, stdinfile=false, env={})
259
260
end
260
261
end
261
262
262
- # for previously empty files, restore the mode, owner and group. The funky
263
- # double-take check is because on Suse defined? doesn't seem to behave
264
- # quite the same as on Debian, RedHat
263
+ # for previously empty files, restore the umask, mode, owner and group.
264
+ # The funky double-take check is because on Suse defined? doesn't seem
265
+ # to behave quite the same as on Debian, RedHat
265
266
if target and ( defined? stat and stat )
266
- File . chmod ( stat . mode , target )
267
+ File . umask ( umask )
268
+ # Need to change group ownership before mode to prevent making the file
269
+ # accessible to the wrong group.
267
270
File . chown ( stat . uid , stat . gid , target )
271
+ File . chmod ( stat . mode , target )
268
272
end
269
273
270
274
return output
0 commit comments