mingw: do not crash on open(NULL, ...)
PATCH 1/1 mingw: do not crash on open(NULL, ...)
Since open() already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.
--- compat/mingw.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
compat/mingw.c +1 -1
@@ -297,7 +297,7 @@ int mingw_open (const char *filename, int oflags, ...) mode =va_arg (args, int);va_end (args); -if (!strcmp (filename,"/dev/null" )) +if (filename && !strcmp (filename,"/dev/null" )) filename ="nul" ; fd =open (filename, oflags, mode);
Signature · 1 line
1.7.2.3.msysgit.0.207.gda0b3
compat/mingw.c int mingw_open (const char *filename, int oflags, ...) · line 303
Quoted 9 lines · Erik Faye-Lund
compat/mingw.c +1
-1@@ -297,7 +297,7 @@ int mingw_open (const char *filename, int oflags, ...) mode =va_arg (args, int);va_end (args); -if (!strcmp (filename,"/dev/null" )) +if (filename && !strcmp (filename,"/dev/null" )) filename ="nul" ; fd =open (filename, oflags, mode);
Good catch, thank you!
-- Hannes
Pat Thoyts
AppliedQuoted 9 lines · Johannes Sixt
Quoted 8 lines · Erik Faye-Lund
compat/mingw.c +1
-1@@ -297,7 +297,7 @@ int mingw_open (const char *filename, int oflags, ...) mode = va_arg(args, int); va_end(args); - if (!strcmp(filename, "/dev/null")) + if (filename && !strcmp(filename, "/dev/null")) filename = "nul";
Quoted 7 lines
compat/mingw.c int mingw_open (const char *filename, int oflags, ...) · line 303
Quoted 1 line
compat/mingw.c +0
-0fd = open(filename, oflags, mode);Good catch, thank you!
Acked-by Johannes Sixt <[email protected]>-- Hannes
Applied to devel and pushed.
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>
I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523
fetch_and_setup_pack_index() apparently pass a NULL-pointer to parse_pack_index(), which in turn pass it to check_packed_git_idx(), which again pass it to open(). This all looks intentional to my (http.c-untrained) eye.
The code in mingw_open was introduced in commit 3e4a1ba (by Johannes Sixt), and the lack of a NULL-check looks like a simple oversight.
Quoted 8 lines · Erik Faye-Lund
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
Quoted 7 lines
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.
Surely, open(NULL) should be rejected by a sane system, and your patch looks sane to me.
But depending on and exploiting the fact sounds like a horrible hack in the caller of parse_pack_index(..., NULL) to me.
Shawn may have intentionally done that in 750ef42 (http-fetch: Use temporary files for pack-*.idx until verified, 2010-04-19), but at least 7b64469 (Allow parse_pack_index on temporary files, 2010-04-19) should have documented that idx_path is allowed to be NULL under what circumstance (and for what purpose it is useful to do so) when it introduced the second parameter to the API.
What were we smoking?
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Erik Faye-Lund
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523
Quoted 8 lines
Quoted 4 lines
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.Surely, open(NULL) should be rejected by a sane system, and your patch looks sane to me.
Since this doesn't seem to be in git.git yet, perhaps you could squash this on top? I didn't notice it in time, but fopen lacked the same check (freopen already had the check). It's not as important, because it doesn't seem like we have any code reaching this path so far, but it would IMO be better to fix this now rather than having to chase down the issue again later...
compat/mingw.c +1 -1
@@ -160,7 +160,7 @@ ssize_t mingw_write(int fd, const void *buf, size_t count)#undef fopenFILE *mingw_fopen (const char *filename,const char *otype) { -if (!strcmp (filename,"/dev/null" )) +if (filename && !strcmp (filename,"/dev/null" )) filename ="nul" ;return fopen (filename, otype); }
Quoted 36 lines · Erik Faye-Lund
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Erik Faye-Lund
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523Quoted 8 lines
Quoted 4 lines
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.Surely, open(NULL) should be rejected by a sane system, and your patch looks sane to me.
Since this doesn't seem to be in git.git yet, perhaps you could squash this on top? I didn't notice it in time, but fopen lacked the same check (freopen already had the check). It's not as important, because it doesn't seem like we have any code reaching this path so far, but it would IMO be better to fix this now rather than having to chase down the issue again later...
compat/mingw.c +0
-0
compat/mingw.c ssize_t mingw_write(int fd, const void *buf, size_t count) · line 166
Quoted 8 lines
compat/mingw.c +1
-1@@ -160,7 +160,7 @@ ssize_t mingw_write(int fd, const void *buf, size_t count) #undef fopen FILE *mingw_fopen (const char *filename, const char *otype) { - if (!strcmp(filename, "/dev/null")) + if (filename && !strcmp(filename, "/dev/null")) filename = "nul"; return fopen(filename, otype); }
I'll apply this to the devel branch and try to remember to squash it on the next rebase-merge.
Cheers,
Pat
Quoted 42 lines · Pat Thoyts
Quoted 41 lines · Erik Faye-Lund
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Erik Faye-Lund
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523Quoted 8 lines
Quoted 4 lines
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.Surely, open(NULL) should be rejected by a sane system, and your patch looks sane to me.
Since this doesn't seem to be in git.git yet, perhaps you could squash this on top? I didn't notice it in time, but fopen lacked the same check (freopen already had the check). It's not as important, because it doesn't seem like we have any code reaching this path so far, but it would IMO be better to fix this now rather than having to chase down the issue again later...
compat/mingw.c +1
-1@@ -160,7 +160,7 @@ ssize_t mingw_write(int fd, const void *buf, size_t count) #undef fopen FILE *mingw_fopen (const char *filename, const char *otype) { - if (!strcmp(filename, "/dev/null")) + if (filename && !strcmp(filename, "/dev/null")) filename = "nul";
Quoted 9 lines
compat/mingw.c ssize_t mingw_write(int fd, const void *buf, size_t count) · line 166
Quoted 3 lines
compat/mingw.c +0
-0return fopen(filename, otype); }I'll apply this to the devel branch and try to remember to squash it on the next rebase-merge.
Cheers,
Pat
Wouldn't it be better to just get this squashed in git.git, and drop the patch in the next rebase-merge? Since this bug is in git.git as well, it makes sense to get the patch merged there, no?
Hi,
Quoted 40 lines · Pat Thoyts
Quoted 39 lines · Erik Faye-Lund
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Erik Faye-Lund
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523Quoted 8 lines
Quoted 4 lines
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.Surely, open(NULL) should be rejected by a sane system, and your patch looks sane to me.
Since this doesn't seem to be in git.git yet, perhaps you could squash this on top? I didn't notice it in time, but fopen lacked the same check (freopen already had the check). It's not as important, because it doesn't seem like we have any code reaching this path so far, but it would IMO be better to fix this now rather than having to chase down the issue again later...
compat/mingw.c +0
-1@@ -160,7 +160,7 @@ ssize_t mingw_write(int fd, const void *buf, size_t count) #undef fopen FILE *mingw_fopen (const char *filename, const char *otype) { - if (!strcmp(filename, "/dev/null"))
Quoted 8 lines
compat/mingw.c ssize_t mingw_write(int fd, const void *buf, size_t count) · line 166
Quoted 5 lines
compat/mingw.c +1
-0+ if (filename && !strcmp(filename, "/dev/null")) filename = "nul"; return fopen(filename, otype); }I'll apply this to the devel branch and try to remember to squash it on the next rebase-merge.
Usually I mark commits like this with ("amend deadcafe") in the commit subject so I do not forget... ;-)
Ciao,
Dscho
(Apparently gmail on a phone insists on top posting)
It looks like this problem was missed by the test suite. Any chance of a test as well? Got to catch those regressions.
Quoted 1 line · Erik Faye-Lund
On Thu, Sep 23, 2010 at 10:35 AM, Erik Faye-Lund <[email protected]>
Quoted 17 lines · wrote:
Quoted 4 lines
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.The code in
mingw_openwas introduced in commit 3e4a1ba (by Johannes Sixt), and the lack of a NULL-check looks like a simple oversight.
Quoted 1 line · Pat Thoyts
(Apparently gmail on a phone insists on top posting)
Fixed ;)
Quoted 18 lines · Erik Faye-Lund
Quoted 17 lines
Quoted 4 lines · Erik Faye-Lund
Since
open()already sets errno correctly for the NULL-case, let's just avoid the problematic strcmp.Signed-off-by Erik Faye-Lund <[email protected]>I guess I should add a comment as to why this patch is needed:
This seems to be the culprit for issue 523 in the msysGit issue
tracker: http://code.google.com/p/msysgit/issues/detail?id=523
fetch_and_setup_pack_index()apparently pass a NULL-pointer toparse_pack_index(), which in turn pass it tocheck_packed_git_idx(), which again pass it toopen(). This all looks intentional to my (http.c-untrained) eye.
Quoted 6 lines
Quoted 2 lines
The code in
mingw_openwas introduced in commit 3e4a1ba (by Johannes Sixt), and the lack of a NULL-check looks like a simple oversight.It looks like this problem was missed by the test suite. Any chance of a test as well? Got to catch those regressions.
I don't think it's practical to test CRT functions directly, but perhaps a test for parse_pack_index() or some level above that might make sense. I tried looking at the this has been done for sha1_file previously, but it seems there's not really any tests at this level. And all tests for http.c seems to depend on Apache being installed (something we do not have in msysGit), so adding a test at this level wouldn't have helped us any...
In other words, I don't think there is any natural point to add a test for this. Feel free to make suggestions, though.
Hi,
Quoted 2 lines · Erik Faye-Lund
The code in
mingw_openwas introduced in commit 3e4a1ba (by Johannes Sixt), and the lack of a NULL-check looks like a simple oversight.
Erik, you have all the information at your finger tips. So why not Cc:
Johannes Sixt, who you blame so openly, so that he has a chance to react (and less of a chance to miss your criticism)?
Ciao,
Dscho