index-pack: do not segfault when keep_name is NULL
PATCH 1/1 index-pack: do not segfault when keep_name is NULL
keep_name is used to print error messages a couple lines down. Reset it to the real path returned by odb_pack_keep() if it's set to NULL by caller.
---
One of these moments I will make git log and friends optionally recognize "Diff-Options:" line in commit message. Adding -U14 in this case should help the reviewer to see how those error messages are printed.
builtin/index-pack.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
builtin/index-pack.c +3 -2
@@ -1283,9 +1283,10 @@ static void final(const char *final_pack_name, const char *curr_pack_name,if (keep_msg) {int keep_fd, keep_msg_len =strlen (keep_msg); -if (!keep_name) +if (!keep_name) { keep_fd =odb_pack_keep (name,sizeof (name), sha1); -else + keep_name = name; + }else keep_fd =open (keep_name,O_RDWR |O_CREAT |O_EXCL ,0600 );if (keep_fd <0 ) {
Signature · 1 line
1.9.0.40.gaa8c3ea
PATCH v2 1/1 index-pack: do not segfault when keep_name is NULL
Use the name that is returned by odb_pack_keep() when the caller passes NULL in keep_name.
--- builtin/index-pack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/index-pack.c +2 -2
@@ -1291,7 +1291,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,if (keep_fd <0 ) {if (errno !=EEXIST )die_errno (_ ("cannot write keep file '%s'" ), - keep_name); + keep_name ? keep_name : name); }else {if (keep_msg_len >0 ) {write_or_die (keep_fd, keep_msg, keep_msg_len);
@@ -1299,7 +1299,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name, }if (close (keep_fd) !=0 )die_errno (_ ("cannot close written keep file '%s'" ), - keep_name); + keep_name ? keep_name : name); report ="keep" ; } }
Signature · 1 line
1.9.0.40.gaa8c3ea
Quoted 18 lines · Nguyễn Thái Ngọc Duy
keep_nameis used to print error messages a couple lines down. Reset it to the real path returned byodb_pack_keep()if it's set to NULL by caller.Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
One of these moments I will make git log and friends optionally recognize "Diff-Options:" line in commit message. Adding -U14 in this case should help the reviewer to see how those error messages are printed.builtin/index-pack.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)builtin/index-pack.c +0
-0
builtin/index-pack.c static void final(const char *final_pack_name, const char *curr_pack_name, · line 1290
Quoted 10 lines
builtin/index-pack.c +3
-2@@ -1283,9 +1283,10 @@ static void final(const char *final_pack_name, const char *curr_pack_name,if (keep_msg) {int keep_fd, keep_msg_len =strlen (keep_msg); -if (!keep_name) +if (!keep_name) { keep_fd =odb_pack_keep (name,sizeof (name), sha1); -else + keep_name = name; + }else keep_fd =open (keep_name,O_RDWR |O_CREAT |O_EXCL ,0600 );
I think this fixes the right problem in a wrong way that hurts longer-term maintainability. Why not do
keep_name ? keep_name : name
at the place where the name is used? Otherwise you will have to worry about affecting later codepaths that may want to try to use !keep_name to switch between two codepaths, no?
Quoted 2 lines
builtin/index-pack.c +0
-0if (keep_fd <0 ) {