Implement the GIT_TRACE_CURL environment variable
v5 cover Implement the GIT_TRACE_CURL environment variable
This is the fifth version but in reality is the complete rewriting of the patches discussed here (here called V1)
$gmane/290520
$gmane/290521
*Changes from V4
($gmane/292867)
- add a better abstraction with the routine setup_curl_trace
- curl_dump : drop the noex parameter, define nopriv boolean as int
- use decimal constant where appropiate
- fix multi-line comment
- redo the authorization header skip with a replace of possible sensitive data.
We prefer to print only:
09:00:53.238330 http.c:534 => Send header: Authorization: <redacted>
intested of
09:00:53.238330 http.c:534 => Send header: Authorization: Basic(o other scheme) <redacted> as it was done in the original proposed suggestion by Jeff King. This is because i think it's better not to print even the authorization scheme. We add also the (previously missing) proxy-authorization case
- curl_dump: fix strbuf memory leak
as suggested by Jeff King
($gmane/292891)
($gmane/292892)
In this series i keep the original curl_dump parsing code, even though it is objectively difficult to read. This is because the same code is used internally by curl to do "ascii-trace" and is also reported in the libcurl code examples and test. I think this may make maintenance of code easier in the future (libcurl new dev, new features and so on)
Of course if the maintainer (or other) believes it is really necessary to rewrite the above code to accept the patches i will do.
*Changes from V3
($gmane/292040)
- add missing static to curl_dump
- reorder the patch order
- tried to fix all (but i am not sure) the problems reported by Julio ($gmane/292055)
- * squash the documentation with the http.c commit.
* in the trace prefix each line to indicate it is about sending a header, and drop the initial hex count
* auto-censor Authorization headers by default
as suggested by Jeff King ($gmane/292074)
*Changes from V2
($gmane/291868)
- fix garbage comment in http.c (i am very sorry for that)
- add final '.' to the commit message for imap-send.c and to other commit messages
- typofix double ; in http.c
- merge the nice cleanup and code refactoring of Ramsay Jones (Thank you very much !!)
- squash the previous commit 2/4
*Changes from V1
- introduced GIT_TRACE_CURL variable with its documentation
- changed the name of the temporary variable "i" in "w" in the helper routine
- used the c escape sequences instead of the hex equivalent
- dropped the previous GIT_DEBUG_CURL env var
- curl_dump and curl_trace factored out to a shared implementation in http.c
Elia Pinto (2):
http.c: implement the GIT_TRACE_CURL environment variable imap-send.c: introduce the GIT_TRACE_CURL enviroment variable
Documentation/git.txt | 8 ++++ http.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++- http.h | 4 ++ imap-send.c | 1 + 4 files changed, 126 insertions(+), 2 deletions(-)
Signature · 1 line
2.8.2.435.ga07a3e0
PATCH v5 1/2 http.c: implement the GIT_TRACE_CURL environment variable
Implement the GIT_TRACE_CURL environment variable to allow a greater degree of detail of GIT_CURL_VERBOSE, in particular the complete transport header and all the data payload exchanged. It might be useful if a particular situation could require a more thorough debugging analysis. Document the new GIT_TRACE_CURL environment variable.
--- Documentation/git.txt | 8 ++++ http.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++- http.h | 4 ++ 3 files changed, 125 insertions(+), 2 deletions(-)
Documentation/git.txt +8 -0
@@ -1076,6 +1076,14 @@ of clones and fetches. cloning of shallow repositories. See 'GIT_TRACE' for available trace output options. +'GIT_TRACE_CURL':: + Enables a curl full trace dump of all incoming and outgoing data, + including descriptive information, of the git transport protocol. + This is similar to doing curl --trace-ascii on the command line. + This option overrides setting the GIT_CURL_VERBOSE environment + variable. + See 'GIT_TRACE' for available trace output options. + 'GIT_LITERAL_PATHSPECS':: Setting this variable to `1` will cause Git to treat all pathspecs literally, rather than as glob patterns. For example,
http.c +113 -2
134 lines not on this page · raw message
http.h +4 -0
@@ -225,4 +225,8 @@ extern int finish_http_object_request(struct http_object_request *freq);extern void abort_http_object_request (struct http_object_request *freq);extern void release_http_object_request (struct http_object_request *freq); +/* Debug callback and setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */ +void setup_curl_trace (CURL *handle); +int curl_trace (CURL *handle,curl_infotype type,char *data,size_t size,void *userp); +#endif /* HTTP_H */
Signature · 1 line
2.8.2.435.ga07a3e0
Re: [PATCHv5 1/2] http.c: implement the GIT_TRACE_CURL environment variable
http.c static void set_curl_keepalive(CURL *c) · line 527
Quoted 7 lines · Elia Pinto
http.c +7
-0+if (nopriv && + (skip_prefix (out.buf + prefix_len,"Authorization:" , &header) + ||skip_prefix (out.buf + prefix_len,"Proxy-Authorization:" , &header))) { +/* The first token is the type, which is OK to log */ +while (isspace (*header)) + header++; +/* Everything else is opaque and possibly sensitive */
The first comment there is now misleading, as we _don't_ keep the first token (though as mentioned elsewhere, I think we should).
http.c static void set_curl_keepalive(CURL *c) · line 539
Quoted 3 lines
http.c +3
-0+void setup_curl_trace (CURL *handle) +{ +if (!trace_want (&trace_curl))return ;
Style: we always put conditional bodies on a new line, even when they are trivial like this.
-Peff
Re: [PATCHv5 1/2] http.c: implement the GIT_TRACE_CURL environment variable
In reply to Elia PintoOn 02/05/16 15:28, Elia Pinto wrote:
[snip]
http.h extern int finish_http_object_request(struct http_object_request *freq); · line 230
Quoted 11 lines
http.h +3
-0@@ -225,4 +225,8 @@ extern int finish_http_object_request(struct http_object_request *freq);extern void abort_http_object_request (struct http_object_request *freq);extern void release_http_object_request (struct http_object_request *freq); +/* Debug callback and setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */ +void setup_curl_trace (CURL *handle); +int curl_trace (CURL *handle,curl_infotype type,char *data,size_t size,void *userp);
Given that you have wrapped the use of the debug callback into the setup_curl_trace() routine (good), do you still need to export the curl_trace() function?
I would make that static, so that only setup_curl_trace() needs to be a public symbol. (I would also re-order the function definitions, so that setup_curl_trace() comes after curl_trace(), but that is a minor point).
ATB,
Ramsay Jones
Re: [PATCHv5 1/2] http.c: implement the GIT_TRACE_CURL environment variable
In reply to Elia PintoQuoted 21 lines · Elia Pinto
http.c +21
-0+static void curl_dump (const char *text,unsigned char *ptr,size_t size,int nopriv) +{ +size_t i; +struct strbuf out =STRBUF_INIT ; +unsigned int width =80 ; + +strbuf_addf (&out,"%s, %10.10ld bytes (0x%8.8lx)\n" , + text, (long )size, (long )size); +trace_strbuf (&trace_curl, &out); + +for (i =0 ; i < size; i += width) { + ... +for (w =0 ; (w < width) && (i + w < size); w++) { +if ((i + w +1 < size) && ptr[i + w] =='\r' + && ptr[i + w +1 ] =='\n' ) { + i += (w +2 - width); +break ; + } +strbuf_addch (&out, (ptr[i + w] >=0x20 ) + && (ptr[i + w] <0x80 ) ? ptr[i + w] :'.' ); + if ((i + w + 2 < size)
http.c static void set_curl_keepalive(CURL *c) · line 535
Quoted 10 lines
http.c +10
-0+ && ptr[i + w + 1] == '\r' + && ptr[i + w + 2] == '\n') { + i += (w +3 - width); +break ; + } + } + ... + } +strbuf_release (&out); +}
There is no change in this hard-to-read double-loop since the previous round?
http.c static void set_curl_keepalive(CURL *c) · line 549
Quoted 5 lines
http.c +5
-0+int curl_trace (CURL *handle,curl_infotype type,char *data,size_t size,void *userp) +{ +const char *text; + (void )handle;/* prevent compiler unused parameter warning if checked */ + (void )userp;/* prevent compiler unused parameter warning if checked */
I really do not want to see these casts. Unused parameters are perfectly normal in a codebase with callback functions, no? I do not think these are the first occurrences of unused parameters in our codebase, and I do not think we have such cast to void to them. Why add this ugliness only to here?
Re: [PATCHv5 1/2] http.c: implement the GIT_TRACE_CURL environment variable
Quoted 11 lines · Junio C Hamano
Review
Quoted 5 lines
(quoted diff) +5
-0+int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp) +{ + const char *text; + (void)handle; /* prevent compiler unused parameter warning if checked */ + (void)userp; /* prevent compiler unused parameter warning if checked */I really do not want to see these casts. Unused parameters are perfectly normal in a codebase with callback functions, no? I do not think these are the first occurrences of unused parameters in our codebase, and I do not think we have such cast to void to them. Why add this ugliness only to here?
Yeah, it is pointless to use -Wunused-parameter in our code base, as it turns up over 1200 hits (though some are repeats from include files). Most are callbacks, but some also look like compat functions. But clearly it's going to be a false positive any time the interface to the function is dictated by something other than the function body.
I generally don't mind quieting false positive warnings if we think it might provide an opportunity for cleanup (i.e., parameters that really _can_ go away). But I don't think gcc provides a great way to do it.
You can mark individual parameters as unused, like:
git-compat-util.h +2 -2
@@ -331,7 +331,7 @@ extern char *gitdirname(char *);#endif #ifndef has_dos_drive_prefix -static inline int git_has_dos_drive_prefix (const char *path) +static inline int git_has_dos_drive_prefix (const char *path __attribute__((unused))) {return 0 ; }
@@ -339,7 +339,7 @@ static inline int git_has_dos_drive_prefix(const char *path)#endif #ifndef skip_dos_drive_prefix -static inline int git_skip_dos_drive_prefix (char **path) +static inline int git_skip_dos_drive_prefix (char **path __attribute__((unused))) {return 0 ; }
That's not too bad in a single-argument function, but for callbacks it can get pretty tedious:
wt-status.c +5 -2
@@ -1300,8 +1300,11 @@ struct grab_1st_switch_cbdata {unsigned char nsha1[20 ]; }; -static int grab_1st_switch (unsigned char *osha1,unsigned char *nsha1, -const char *email,unsigned long timestamp,int tz, +static int grab_1st_switch (unsigned char *osha1 __attribute__((unused)), +unsigned char *nsha1, +const char *email __attribute__((unused)), +unsigned long timestamp __attribute__((unused)), +int tz __attribute__((unused)),const char *message,void *cb_data) {struct grab_1st_switch_cbdata *cb = cb_data;
It would be much nicer if we had some way of declaring the whole _function_ as having an interface dictated elsewhere. Then it becomes a single attribute per callback function, and actually tells the human reader something useful: not "I happen to not need these variables right now", but "my interface is specified elsewhere and not up for debate".
But AFAIK, there's no such attribute.
-Peff
Re: [PATCHv5 1/2] http.c: implement the GIT_TRACE_CURL environment variable
In reply to Elia Pintohttp.c static void set_curl_keepalive(CURL *c) · line 550
Quoted 6 lines · Elia Pinto
http.c +6
-0+int curl_trace (CURL *handle,curl_infotype type,char *data,size_t size,void *userp) +{ +const char *text; + (void )handle;/* prevent compiler unused parameter warning if checked */ + (void )userp;/* prevent compiler unused parameter warning if checked */ +int nopriv =0 ;/*
This decl-after-statment breaks our build.
PATCH v5 2/2 imap-send.c: introduce the GIT_TRACE_CURL environment variable
In reply to Elia PintoPermit the use of the GIT_TRACE_CURL environment variable calling the curl_trace and curl_dump http.c helper routine.
--- imap-send.c | 1 + 1 file changed, 1 insertion(+)
imap-send.c +1 -0
@@ -1443,6 +1443,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc)if (0 < verbosity ||getenv ("GIT_CURL_VERBOSE" ))curl_easy_setopt (curl,CURLOPT_VERBOSE ,1L ); +setup_curl_trace (curl);return curl; }
Signature · 1 line
2.8.2.435.ga07a3e0
Quoted 7 lines · Elia Pinto
- redo the authorization header skip with a replace of possible sensitive data. We prefer to print only:
09:00:53.238330 http.c:534 => Send header: Authorization: <redacted> intested of 09:00:53.238330 http.c:534 => Send header: Authorization: Basic(o other scheme) <redacted>as it was done in the original proposed suggestion by Jeff King. This is because i think it's better not to print even the authorization scheme.
I'm not sure I agree. If you're debugging curl's auth selection, that's omitting an important piece of data. And unlike the actual credential, I don't think it's particularly secret (and in many cases can be deduced from the "WWW-Authenticate" header the server sends, coupled with curl's code).
Quoted 1 line
We add also the (previously missing) proxy-authorization case
Good catch.
Quoted 5 lines
In this series i keep the original
curl_dumpparsing code, even though it is objectively difficult to read. This is because the same code is used internally by curl to do "ascii-trace" and is also reported in the libcurl code examples and test. I think this may make maintenance of code easier in the future (libcurl new dev, new features and so on)
I don't agree with this line of reasoning. The code in question is purely about how we format the output buffer, not about parsing what curl gives us. We _should_ be diverging if we prefer a different output format. And I don't think it's a question just of readability (though I do agree the existing one is hard to read); it also foils the redaction of the authorization header.
-Peff