-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle UNC paths correctly when making cURL relocatable #51
Handle UNC paths correctly when making cURL relocatable #51
Conversation
The code to make cURL relocatable simplifies/normalizes paths, e.g. reducing multiple forward slashes to a single one. This is okay in general, but at the beginning of the path, a double slash has a special meaning: it denotes a UNC path of the form //<host>/<path>. It would therefore be a mistake to reduce those first two slashes to a single one: otherwise it would refer to the absolute path relative to the current directory's drive. Let's preserve the double slashes. This fixes git-for-windows/git#3266 Signed-off-by: Johannes Schindelin <[email protected]>
@@ -156,7 +156,7 @@ index 000000000..c09458e95 | |||
+ *path_p = '/'; | |||
+ } | |||
+ /* Replace any '//' with '/' */ | |||
+ path_p = path; | |||
+ path_p = path + !!*path; /* skip first character, if any, to handle UNC paths correctly */ | |||
+ while ((path_p = strstr (path_p, "//")) != NULL) | |||
+ { | |||
+ memmove (path_p, path_p + 1, path_size--); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's unrelated to the change, but it looks like a bug to me.
This memmove() call will modify data located after the "path" string in memory for most of the cases.
Like if the "path" is "foobar//goo" it will be called like memmove("//goo", "/goo", 11), so it will move data located after the end of the "path" string unless the memmove() has a specific implementation to check end-of-string (that would be quite unusual).
I'd expect it to be something like:
memmove (path_p, path_p + 1, strlen(path_p + 1) + 1);
or to be shorter:
memmove (path_p, path_p + 1, strlen(path_p));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you're right... This bug exists in MSYS2, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a much better version would look like this:
#define IS_SLASH(c) ((c) == '/' || (c) == '\\')
void
sanitize_path(char *path)
{
int i, j = IS_SLASH(*path) ? 1 : 0;
for (i = j; path[i]; i++) {
if (!IS_SLASH(path[i]))
path[j++] = path[i];
else {
/* reduce runs of slashes into a single forward slash */
while (IS_SLASH(path[i+1]))
i++;
path[j++] = '/';
}
}
path[j] = '\0';
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to set aside time at some point in the near future to get this one in.
Remote HTTPS repositories [could not be accessed from within portable Git installed into a network share](git-for-windows/git#3266). This [has been fixed](git-for-windows/MINGW-packages#51). Signed-off-by: Johannes Schindelin <[email protected]>
This fixes git-for-windows/git#3266