Fix dir sep handling of GIT_ASKPASS on Windows
PATCH 1/1 Fix dir sep handling of GIT_ASKPASS on Windows
From: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin, GIT_ASKPASS failed to run for relative and absolute paths containing only backslashes as directory separators.
The reason was that git assumed that if there are no forward slashes in the executable path, it has to search for the executable on the PATH.
The fix is to look for OS specific directory separators, not just forward slashes.
---
Fix dir sep handling of GIT_ASKPASS on Windows
On Windows with git installed through cygwin, GIT_ASKPASS failed to run for relative and absolute paths containing only backslashes as directory separators.
The reason was that git assumed that if there are no forward slashes in the executable path, it has to search for the executable on the PATH.
The fix is to look for OS specific directory separators, not just forward slashes.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-587%2Fr0mai%2Ffix-prepare_cmd-windows-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-587/r0mai/fix-prepare_cmd-windows-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/587
run-command.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
run-command.c +5 -5
@@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) }/* -* If there are no '/' characters in the command then perform a path -* lookup and use the resolved path as the command to exec. If there -* are '/' characters, we have exec attempt to invoke the command -* directly. +* If there are no dir separator characters in the command then perform +* a path lookup and use the resolved path as the command to exec. If +* there are dir separator characters, we have exec attempt to invoke +* the command directly. */ -if (!strchr (out->argv[1 ],'/' )) { +if (find_last_dir_sep (out->argv[1 ]) ==NULL ) {char *program =locate_in_PATH (out->argv[1 ]);if (program) {free ((char *)out->argv[1 ]);
base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
Signature · 1 line
gitgitgadget
Quoted 8 lines · András Kucsma via GitGitGadget
From: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin,
GIT_ASKPASSfailed to run for relative and absolute paths containing only backslashes as directory separators.The reason was that git assumed that if there are no forward slashes in the executable path, it has to search for the executable on the PATH.
Also if I were reading the discussion correctly, there was a doubt about locate_in_PATH() that may not work on Windows for at least two reasons. Is it OK to ignore these issues, and if so why?
I know if you have a full path, a broken locate_in_PATH() would be skipped and won't cause an immediate issue, but this change to make the code realize that "a\\b" is not asking to search in %PATH% feels just a beginning of a fix, not the whole fix, at least to me.
Quoted 2 lines
The fix is to look for OS specific directory separators, not just forward slashes.
Yes, but it is quite unfortunate that you would use a function that has to scan the string to the end because it asks for the last one.
Perhaps introduce
--------------------------------------------------
#ifndef has_dir_sep
static inline int git_has_dir_sep(const char *path)
{
return !!strchr(path, '/');
}#define has_dir_sep(path) git_has_dir_sep(path)
#endif
--------------------------------------------------
in <git-compat-util.h>, with a replacement definition in <compat/win32/path-utils.h> that may read
--------------------------------------------------
#define has_dir_sep(path) win32_has_dir_sep(path)
static inline int has_dir_sep(const char *path)
{
/*
* See how long the non-separator part of the given path is, and
* if and only if it covers the whole path (i.e. path[len] is NUL),
* there is no separator in the path---otherwise there is a separaptor.
*/
size_t len = strcspn(path, "/\\");
return !!path[len];
}--------------------------------------------------
and use that instead?
Quoted 24 lines
run-command.c +5
-5@@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) }/* -* If there are no '/' characters in the command then perform a path -* lookup and use the resolved path as the command to exec. If there -* are '/' characters, we have exec attempt to invoke the command -* directly. +* If there are no dir separator characters in the command then perform +* a path lookup and use the resolved path as the command to exec. If +* there are dir separator characters, we have exec attempt to invoke +* the command directly. */ -if (!strchr (out->argv[1 ],'/' )) { +if (find_last_dir_sep (out->argv[1 ]) ==NULL ) {char *program =locate_in_PATH (out->argv[1 ]);if (program) {free ((char *)out->argv[1 ]);base-commit:
274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
PATCH v2 1/1 Fix dir sep handling of GIT_ASKPASS on Windows
In reply to András Kucsma via GitGitGadgetFrom: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin, GIT_ASKPASS failed to run for relative and absolute paths containing only backslashes as directory separators.
The reason was that git assumed that if there are no forward slashes in the executable path, it has to search for the executable on the PATH.
The fix is to look for OS specific directory separators, not just forward slashes.
---
Fix dir sep handling of GIT_ASKPASS on Windows
On Windows with git installed through cygwin, GIT_ASKPASS failed to run for relative and absolute paths containing only backslashes as directory separators.
The reason was that git assumed that if there are no forward slashes in the executable path, it has to search for the executable on the PATH.
The fix is to look for OS specific directory separators, not just forward slashes.
Changes since v1:
* Avoid scanning the whole path for a directory separator even if one is found earlier as suggested by Junio C Hamano.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-587%2Fr0mai%2Ffix-prepare_cmd-windows-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-587/r0mai/fix-prepare_cmd-windows-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/587
Range-diff vs v1:
1: 8fbfbec0d38 ! 1: 947931ac568 Fix dir sep handling of GIT_ASKPASS on Windows
@@ -14,6 +14,47 @@
Signed-off-by: Andras Kucsma <[email protected]>
+ diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h
+ --- a/compat/win32/path-utils.h
+ +++ b/compat/win32/path-utils.h
+@@
+ return ret;
+ }
+ #define find_last_dir_sep win32_find_last_dir_sep
++static inline int win32_has_dir_sep(const char *path)
++{
++ /*
++ * See how long the non-separator part of the given path is, and
++ * if and only if it covers the whole path (i.e. path[len] is NULL),
++ * there is no separator in the path---otherwise there is a separator.
++ */
++ size_t len = strcspn(path, "/\\");
++ return !!path[len];
++}
++#define has_dir_sep(path) win32_has_dir_sep(path)
+ int win32_offset_1st_component(const char *path);
+ #define offset_1st_component win32_offset_1st_component
+
+
+ diff --git a/git-compat-util.h b/git-compat-util.h
+ --- a/git-compat-util.h
+ +++ b/git-compat-util.h
+@@
+ #define find_last_dir_sep git_find_last_dir_sep
+ #endif
+
++#ifndef has_dir_sep
++static inline int git_has_dir_sep(const char *path)
++{
++ return !!strchr(path, '/');
++}
++#define has_dir_sep(path) git_has_dir_sep(path)
++#endif
++
+ #ifndef query_user_email
+ #define query_user_email() NULL
+ #endif
+
diff --git a/run-command.c b/run-command.c
--- a/run-command.c
+++ b/run-command.c
@@ -31,7 +72,7 @@
+ * the command directly.
*/
- if (!strchr(out->argv[1], '/')) {
-+ if (find_last_dir_sep(out->argv[1]) == NULL) {
++ if (!has_dir_sep(out->argv[1])) {
char *program = locate_in_PATH(out->argv[1]);
if (program) {
free((char *)out->argv[1]);compat/win32/path-utils.h | 11 +++++++++++ git-compat-util.h | 8 ++++++++ run-command.c | 10 +++++----- 3 files changed, 24 insertions(+), 5 deletions(-)
compat/win32/path-utils.h +11 -0
@@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path)return ret; }#define find_last_dir_sep win32_find_last_dir_sep +static inline int win32_has_dir_sep (const char *path) +{ +/* +* See how long the non-separator part of the given path is, and +* if and only if it covers the whole path (i.e. path[len] is NULL), +* there is no separator in the path---otherwise there is a separator. +*/ +size_t len =strcspn (path,"/\\" ); +return !!path[len]; +} +#define has_dir_sep (path) win32_has_dir_sep(path)int win32_offset_1st_component (const char *path);#define offset_1st_component win32_offset_1st_component
git-compat-util.h +8 -0
@@ -389,6 +389,14 @@ static inline char *git_find_last_dir_sep(const char *path)#define find_last_dir_sep git_find_last_dir_sep#endif +#ifndef has_dir_sep +static inline int git_has_dir_sep (const char *path) +{ +return !!strchr (path,'/' ); +} +#define has_dir_sep (path) git_has_dir_sep(path) +#endif +#ifndef query_user_email#define query_user_email () NULL#endif
run-command.c +5 -5
@@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) }/* -* If there are no '/' characters in the command then perform a path -* lookup and use the resolved path as the command to exec. If there -* are '/' characters, we have exec attempt to invoke the command -* directly. +* If there are no dir separator characters in the command then perform +* a path lookup and use the resolved path as the command to exec. If +* there are dir separator characters, we have exec attempt to invoke +* the command directly. */ -if (!strchr (out->argv[1 ],'/' )) { +if (!has_dir_sep (out->argv[1 ])) {char *program =locate_in_PATH (out->argv[1 ]);if (program) {free ((char *)out->argv[1 ]);
base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
Signature · 1 line
gitgitgadget
Thanks for working on this. I have 1 or 2 nits/questions, please see below.
Quoted 3 lines · András Kucsma via GitGitGadget
From: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin,
GIT_ASKPASSfailed to run
My understanding is, that git under cygwin needs this patch (so to say), but isn't it so, that even Git for Windows has the same issue ? The headline of the patch and the indicate so.
How about the following ?
On Windows GIT_ASKPASS failed to run for relative and absolute paths containing only backslashes as directory separators.
The reason was that Git assumed that if there are no forward slashes in the executable path, it has to search for the executable on the PATH.
The fix is to look for OS specific directory separators, not just forward slashes, so introduce a helper function has_dir_sep() and use it in run-command.
Quoted 11 lines · Torsten Bögershausen
Thanks for working on this. I have 1 or 2 nits/questions, please see below.
Quoted 3 lines · András Kucsma via GitGitGadget
From: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin,
GIT_ASKPASSfailed to runMy understanding is, that git under cygwin needs this patch (so to say), but isn't it so, that even Git for Windows has the same issue ? The headline of the patch and the indicate so.
Git for Windows does not have this issue, because there GIT_WINDOWS_NATIVE is defined, which is not true under Cygwin:
https://github.com/git/git/blob/274b9cc2/git-compat-util.h#L157-L165
You can see in start_command() that there are separate implementations based on GIT_WINDOWS_NATIVE. The problematic code is in prepare_cmd, which is not called in the branch where GIT_WINDOWS_NATIVE is defined:
https://github.com/git/git/blob/274b9cc2/run-command.c#L740
This means, that cygwin is running in the Unix-like branch of the code, even though it supports backslashes in its paths.
Quoted 5 lines · Torsten Bögershausen
Quoted 1 line
On Windows with git installed through cygwin,
GIT_ASKPASSfailed to runMy understanding is, that git under cygwin needs this patch (so to say), but isn't it so, that even Git for Windows has the same issue ? The headline of the patch and the indicate so.
Yes, I agree that the commit is mistitled. It is not specific to Windows (it only is Cygwin, as the support for native Windows goes a separate codepath), and it is not specific to GIT_ASKPASS, either.
Quoted 7 lines · András Kucsma via GitGitGadget
From: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin,
GIT_ASKPASSfailed to run for relative and absolute paths containing only backslashes as directory separators.Subject: [PATCH v2] Fix dir sep handling of
GIT_ASKPASSon Windows
Isn't it curious that there is nothing in the code that was touched that is specific to GIT_ASKPASS? We shouldn't have to see that in the title.
Perhaps
Subject: run-command: notice needs for PATH-lookup correctly on Cygwin
On Cygwin, the codepath for POSIX-like systems is taken in run-command.c::start_command(). The prepare_cmd() helper function is called to decide if the command needs to be looked up in the $PATH, and the logic there is to do the PATH-lookup if and only if it does not have any slash '/' in it.
Unfortunately, a end-user can give "c:\program files\askpass" or "a\b\c" to be absolute or relative path to the command, but in these strings there is no '/'. We end up attempting to run the command by appending the absoluter or relative path after each colon-separated component of $PATH.
Instead, introduce a has_dir_sep(path) helper function to abstract away the difference between true POSIX and Cygwin, and use it to make the decision for PATH-lookup.
Having said all that, I am not sure if we need to change anything.
As Cygwin is about trying to mimicking UNIXy environment as much as possible, shouldn't "GIT_ASKPASS=//c/program files/askpass" the way end-users would expect to work, not the one that uses backslashes?
And if the user pretends to be on UNIXy system by using Cygwin by using slashes when specifying these commands run via the run_command API, the code makes the decision for PATH-lookup quite correctly, no?
So...
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · András Kucsma via GitGitGadget
From: Andras Kucsma <[email protected]>
On Windows with git installed through cygwin,
GIT_ASKPASSfailed to run for relative and absolute paths containing only backslashes as directory separators.
Quoted 5 lines
Quoted 1 line
Subject: [PATCH v2] Fix dir sep handling of
GIT_ASKPASSon WindowsIsn't it curious that there is nothing in the code that was touched that is specific to
GIT_ASKPASS? We shouldn't have to see that in the title.
You're completely right, I'll rephrase the commit message based on your suggestion and resubmit.
Quoted 6 lines
Having said all that, I am not sure if we need to change anything.
As Cygwin is about trying to mimicking UNIXy environment as much as possible, shouldn't "GIT_ASKPASS=//c/program files/askpass" the way end-users would expect to work, not the one that uses backslashes?
Quoted 6 lines
And if the user pretends to be on UNIXy system by using Cygwin by using slashes when specifying these commands run via the
run_commandAPI, the code makes the decision for PATH-lookup quite correctly, no?So...
Cygwin provides a Unix like environment, while also maintaining Windows compatibility, at least as far as path handling is concerned. As a quick test, fopen can handle forward slashes, backslashes too. These four all work under cygwin:
fopen("C:\\file.txt", "r");fopen("C:/file.txt", "r");fopen("/cygdrive/c/file.txt", "r");fopen("/cygdrive\\c\\file.txt", "r");
There seems to be a precedent to support Cygwin as a kind of "hybrid" platform in the git codebase. In git-compat-util.h, the compat/win32/path-utils.h header is included, but GIT_WINDOWS_NATIVE is not defined.
https://github.com/git/git/blob/a7d14a442/git-compat-util.h#L204-L206
https://github.com/git/git/blob/a7d14a442/git-compat-util.h#L157-L165
The compat/win32/path-utils.h header mostly provides utilities dealing with directory separator related logic on Windows, but these utilities are being used in the Unixy code paths on Cygwin.
The current version of the patch fits into this pattern. It only changes behaviour under Cygwin, not touching pure Windows and non-Cygwin Unix variants at all.
PATCH v3 1/1 run-command: trigger PATH lookup properly on Cygwin
In reply to András Kucsma via GitGitGadgetFrom: Andras Kucsma <[email protected]>
On Cygwin, the codepath for POSIX-like systems is taken in run-command.c::start_command(). The prepare_cmd() helper function is called to decide if the command needs to be looked up in the PATH. The logic there is to do the PATH-lookup if and only if it does not have any slash '/' in it. If this test passes we end up attempting to run the command by appending the string after each colon-separated component of PATH.
The Cygwin environment supports both Windows and POSIX style paths, so both forwardslahes '/' and back slashes '\' can be used as directory separators for any external program the user supplies.
Examples for path strings which are being incorrectly searched for in the PATH instead of being executed as is:
- "C:\Program Files\some-program.exe"
- "a\b\c.exe"
To handle these, the PATH lookup detection logic in prepare_cmd() is taught to know about this Cygwin quirk, by introducing has_dir_sep(path) helper function to abstract away the difference between true POSIX and Cygwin systems.
---
run-command: trigger PATH lookup properly on Cygwin
On Cygwin, the codepath for POSIX-like systems is taken in run-command.c::start_command(). The prepare_cmd() helper function is called to decide if the command needs to be looked up in the PATH. The logic there is to do the PATH-lookup if and only if it does not have any slash '/' in it. If this test passes we end up attempting to run the command by appending the string after each colon-separated component of PATH.
The Cygwin environment supports both Windows and POSIX style paths, so both forwardslahes '/' and back slashes '' can be used as directory separators for any external program the user supplies.
Examples for path strings which are being incorrectly searched for in the PATH instead of being executed as is:
* "C:\Program Files\some-program.exe"
* "a\b\c.exe"
To handle these, the PATH lookup detection logic in prepare_cmd() is taught to know about this Cygwin quirk, by introducing has_dir_sep(path) helper function to abstract away the difference between true POSIX and Cygwin systems.
Changes since v1:
* Avoid scanning the whole path for a directory separator even if one is found earlier as suggested by Junio C Hamano. Changes since v2:
* Rephrased the commit message based on Junio's suggestion.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-587%2Fr0mai%2Ffix-prepare_cmd-windows-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-587/r0mai/fix-prepare_cmd-windows-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/587
Range-diff vs v2:
1: 947931ac568 ! 1: fd3cbd51635 Fix dir sep handling of GIT_ASKPASS on Windows
@@ -1,16 +1,30 @@
Author: Andras Kucsma <[email protected]>
- Fix dir sep handling of GIT_ASKPASS on Windows
+ run-command: trigger PATH lookup properly on Cygwin
- On Windows with git installed through cygwin, GIT_ASKPASS failed to run
- for relative and absolute paths containing only backslashes as directory
- separators.
+ On Cygwin, the codepath for POSIX-like systems is taken in
+ run-command.c::start_command(). The prepare_cmd() helper
+ function is called to decide if the command needs to be looked
+ up in the PATH. The logic there is to do the PATH-lookup if
+ and only if it does not have any slash '/' in it. If this test
+ passes we end up attempting to run the command by appending the
+ string after each colon-separated component of PATH.
- The reason was that git assumed that if there are no forward slashes in
- the executable path, it has to search for the executable on the PATH.
+ The Cygwin environment supports both Windows and POSIX style
+ paths, so both forwardslahes '/' and back slashes '\' can be
+ used as directory separators for any external program the user
+ supplies.
- The fix is to look for OS specific directory separators, not just
- forward slashes.
+ Examples for path strings which are being incorrectly searched
+ for in the PATH instead of being executed as is:
+
+ - "C:\Program Files\some-program.exe"
+ - "a\b\c.exe"
+
+ To handle these, the PATH lookup detection logic in prepare_cmd()
+ is taught to know about this Cygwin quirk, by introducing
+ has_dir_sep(path) helper function to abstract away the difference
+ between true POSIX and Cygwin systems.
compat/win32/path-utils.h | 11 +++++++++++ git-compat-util.h | 8 ++++++++ run-command.c | 10 +++++----- 3 files changed, 24 insertions(+), 5 deletions(-)
compat/win32/path-utils.h +11 -0
@@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path)return ret; }#define find_last_dir_sep win32_find_last_dir_sep +static inline int win32_has_dir_sep (const char *path) +{ +/* +* See how long the non-separator part of the given path is, and +* if and only if it covers the whole path (i.e. path[len] is NULL), +* there is no separator in the path---otherwise there is a separator. +*/ +size_t len =strcspn (path,"/\\" ); +return !!path[len]; +} +#define has_dir_sep (path) win32_has_dir_sep(path)int win32_offset_1st_component (const char *path);#define offset_1st_component win32_offset_1st_component
git-compat-util.h +8 -0
@@ -389,6 +389,14 @@ static inline char *git_find_last_dir_sep(const char *path)#define find_last_dir_sep git_find_last_dir_sep#endif +#ifndef has_dir_sep +static inline int git_has_dir_sep (const char *path) +{ +return !!strchr (path,'/' ); +} +#define has_dir_sep (path) git_has_dir_sep(path) +#endif +#ifndef query_user_email#define query_user_email () NULL#endif
run-command.c +5 -5
@@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) }/* -* If there are no '/' characters in the command then perform a path -* lookup and use the resolved path as the command to exec. If there -* are '/' characters, we have exec attempt to invoke the command -* directly. +* If there are no dir separator characters in the command then perform +* a path lookup and use the resolved path as the command to exec. If +* there are dir separator characters, we have exec attempt to invoke +* the command directly. */ -if (!strchr (out->argv[1 ],'/' )) { +if (!has_dir_sep (out->argv[1 ])) {char *program =locate_in_PATH (out->argv[1 ]);if (program) {free ((char *)out->argv[1 ]);
base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
Signature · 1 line
gitgitgadget
Re: [PATCH v3] run-command: trigger PATH lookup properly on Cygwin
Quoted 1 line · András Kucsma via GitGitGadget
Subject: Re: [PATCH v3] run-command: trigger PATH lookup properly on Cygwin
You phrased it much better than my earlier attempt. Succinct, accurate and to the point. Good.
Quoted 10 lines
compat/win32/path-utils.h | 11 +++++++++++ git-compat-util.h | 8 ++++++++ run-command.c | 10 +++++----- 3 files changed, 24 insertions(+), 5 deletions(-)compat/win32/path-utils.h +0
-0
compat/win32/path-utils.h static inline char *win32_find_last_dir_sep(const char *path) · line 27
Quoted 8 lines
compat/win32/path-utils.h +5
-0@@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path)return ret; }#define find_last_dir_sep win32_find_last_dir_sep +static inline int win32_has_dir_sep (const char *path) +{ +/* +* See how long the non-separator part of the given path is, and +* if and only if it covers the whole path (i.e. path[len] is NULL),
The name of the ASCII character '\0' is NUL, not NULL (I'll fix it while applying, so no need to resend if you do not have anything else that needs updating).
Otherwise, the patch looks good.
Thanks.
Re: [PATCH v3] run-command: trigger PATH lookup properly on Cygwin
Quoted 3 lines · Junio C Hamano
The name of the ASCII character '\0' is NUL, not NULL (I'll fix it while applying, so no need to resend if you do not have anything else that needs updating).
Right, sorry! I have no other updates.
Quoted 3 lines
Otherwise, the patch looks good.
Thanks.
Thanks for the help!
Re: [PATCH v3] run-command: trigger PATH lookup properly on Cygwin
In reply to Junio C HamanoQuoted 1 line · Junio C Hamano
The name of the ASCII character '\0' is NUL, not NULL
NUL is not a name, it is an abbreviation or acronym. Its name is the Null character.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [PATCH v3] run-command: trigger PATH lookup properly on Cygwin
Quoted 6 lines · Andreas Schwab
Quoted 1 line · Junio C Hamano
The name of the ASCII character '\0' is NUL, not NULL
NUL is not a name, it is an abbreviation or acronym. Its name is the Null character.
OK, let's put it differently.
compat/win32/path-utils.h static inline char *win32_find_last_dir_sep(const char *path) · line 27
Quoted 2 lines
compat/win32/path-utils.h +2
-0+* See how long the non-separator part of the given path is, and +* if and only if it covers the whole path (i.e. path[len] is NULL),
When referring to character '\0' like so, write "NUL", not "NULL", as the latter is how you write a null pointer.