On 8. 7. 25 02:18, Branko Čibej wrote:
When Subversion is built with SVN_DEBUG defined, error messages
contain a call trace with absolute paths to the source files. This
potentially exposes sensitive user info, such as project or company
names, when people post error reports to the 'net or e-mail.
As luck would have it, Subversion's source tree layout has an easily
recognisable root for all the sources. This patch changes the paths
displayed in the error messages to be relative to the source directory.
The absolute paths are still embedded in the object files and
libraries, but at least it's less likely that user will publish
sensitive info by mistake.
As a bonus, the lines in the error reports are shorter.
Before:
$ ./subversion/svn/svn cofile:///dev/null
/Users/brane/src/svn/repos/trunk/subversion/svn/checkout-cmd.c:177,
/Users/brane/src/svn/repos/trunk/subversion/libsvn_client/checkout.c:318,
/Users/brane/src/svn/repos/trunk/subversion/libsvn_client/checkout.c:188,
/Users/brane/src/svn/repos/trunk/subversion/libsvn_client/ra.c:557,
/Users/brane/src/svn/repos/trunk/subversion/libsvn_client/ra.c:425,
/Users/brane/src/svn/repos/trunk/subversion/libsvn_ra/ra_loader.c:399:
(apr_err=SVN_ERR_RA_CANNOT_CREATE_SESSION)
svn: E170013: Unable to connect to a repository at URL 'file:///dev/null'
/Users/brane/src/svn/repos/trunk/subversion/libsvn_ra_local/ra_plugin.c:597,
/Users/brane/src/svn/repos/trunk/subversion/libsvn_ra_local/split_url.c:49:
(apr_err=SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED)
svn: E180001: Unable to open repository 'file:///dev/null'
After:
$ ./subversion/svn/svn cofile:///dev/null
subversion/svn/checkout-cmd.c:177,
subversion/libsvn_client/checkout.c:318,
subversion/libsvn_client/checkout.c:188,
subversion/libsvn_client/ra.c:557,
subversion/libsvn_client/ra.c:425,
subversion/libsvn_ra/ra_loader.c:399: (apr_err=SVN_ERR_RA_CANNOT_CREATE_SESSION)
svn: E170013: Unable to connect to a repository at URL 'file:///dev/null'
subversion/libsvn_ra_local/ra_plugin.c:597,
subversion/libsvn_ra_local/split_url.c:49:
(apr_err=SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED)
svn: E180001: Unable to open repository 'file:///dev/null'
Here's an updated patch that, IMO, makes the output more readable.
Even afterer:
$ ./subversion/svn/svn cofile:///dev/null
.../subversion/svn/checkout-cmd.c:177,
.../subversion/libsvn_client/checkout.c:318,
.../subversion/libsvn_client/checkout.c:188,
.../subversion/libsvn_client/ra.c:557,
.../subversion/libsvn_client/ra.c:425,
.../subversion/libsvn_ra/ra_loader.c:399:
(apr_err=SVN_ERR_RA_CANNOT_CREATE_SESSION)
svn: E170013: Unable to connect to a repository at URL 'file:///dev/null'
.../subversion/libsvn_ra_local/ra_plugin.c:597,
.../subversion/libsvn_ra_local/split_url.c:49:
(apr_err=SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED)
svn: E180001: Unable to open repository 'file:///dev/null'
-- Brane
[[[
Show only paths relative to the root of the source tree in
the debug-mode error trace messages.
* subversion/libsvn_subr/error.c
(srcdir_relative_path): New; finds the last occurence of "/subversion/"
in the given path (expanded from __FILE__).
(svn_error__locate): Alles ist relativ.
(print_error): Prepend ".../" (or "...\") to the relative path.
Incidentally, actually use the converted 'path_utf8' instead of
throwing it away. This was a bug left over from ye olden days.
]]]
Index: subversion/libsvn_subr/error.c
===================================================================
--- subversion/libsvn_subr/error.c (revision 1926967)
+++ subversion/libsvn_subr/error.c (working copy)
@@ -24,6 +24,9 @@
^L
#include <stdarg.h>
+#define APR_WANT_STRFUNC
+#include <apr_want.h>
+
#include <apr_general.h>
#include <apr_pools.h>
#include <apr_strings.h>
@@ -116,6 +119,39 @@ static const char SVN_FILE_LINE_UNDEFINED[] = "svn
#undef svn_error_quick_wrapf
#undef svn_error_wrap_apr
+#ifdef SVN_DEBUG
+/* Strip away FILE's components until we find the last '/subversion/'.
+ This way, we only display relative paths within our source tree. */
+static const char *srcdir_relative_path(const char *file)
+{
+ static const char separators[3] = { '/', SVN_PATH_LOCAL_SEPARATOR, '\0' };
+ static const char subversion[] = "subversion";
+ const apr_size_t length = sizeof(subversion) - 1;
+ apr_size_t n = strcspn(file, separators);
+
+ while (file[n])
+ {
+ ++n;
+ if (file[n])
+ {
+ if (0 == strncmp(&file[n], subversion, length)
+ && (file[n + length] == 0
+ || file[n + length] == separators[0]
+ || file[n + length] == separators[1]))
+ {
+ file = &file[n];
+ n = length;
+ }
+ else
+ {
+ n += strcspn(&file[n], separators);
+ }
+ }
+ }
+ return file;
+}
+#endif /* SVN_DEBUG */
+
/* Note: Although this is a "__" function, it was historically in the
* public ABI, so we can never change it or remove its signature, even
* though it is now only used in SVN_DEBUG mode. */
@@ -123,6 +159,7 @@ void
svn_error__locate(const char *file, long line)
{
#ifdef SVN_DEBUG
+ const char *const relfile = srcdir_relative_path(file);
# if APR_HAS_THREADS
static volatile svn_atomic_t init_status = 0;
svn_atomic__init_once_no_error(&init_status, locate_init_once, NULL);
@@ -130,7 +167,7 @@ svn_error__locate(const char *file, long line)
if (error_file_key && error_line_key)
{
apr_status_t status;
- status = apr_threadkey_private_set((char*)file, error_file_key);
+ status = apr_threadkey_private_set((char*)relfile, error_file_key);
if (status == APR_SUCCESS)
status = apr_threadkey_private_set((void*)line, error_line_key);
if (status == APR_SUCCESS)
@@ -138,7 +175,7 @@ svn_error__locate(const char *file, long line)
}
# endif /* APR_HAS_THREADS */
- error_file = file;
+ error_file = relfile;
error_line = line;
#endif /* SVN_DEBUG */
}
@@ -586,8 +623,9 @@ print_error(svn_error_t *err, FILE *stream, const
if (err->file
&& !(temp_err = svn_utf_cstring_to_utf8(&file_utf8, err->file,
err->pool)))
- svn_error_clear(svn_cmdline_fprintf(stream, err->pool,
- "%s:%ld", err->file, err->line));
+ svn_error_clear(svn_cmdline_fprintf(stream, err->pool, "...%c%s:%ld",
+ SVN_PATH_LOCAL_SEPARATOR,
+ file_utf8, err->line));
else
{
svn_error_clear(svn_cmdline_fputs(SVN_FILE_LINE_UNDEFINED,
Index: subversion/libsvn_subr/error.c
===================================================================
--- subversion/libsvn_subr/error.c (revision 1926967)
+++ subversion/libsvn_subr/error.c (working copy)
@@ -24,6 +24,9 @@
#include <stdarg.h>
+#define APR_WANT_STRFUNC
+#include <apr_want.h>
+
#include <apr_general.h>
#include <apr_pools.h>
#include <apr_strings.h>
@@ -116,6 +119,39 @@ static const char SVN_FILE_LINE_UNDEFINED[] = "svn
#undef svn_error_quick_wrapf
#undef svn_error_wrap_apr
+#ifdef SVN_DEBUG
+/* Strip away FILE's components until we find the last '/subversion/'.
+ This way, we only display relative paths within our source tree. */
+static const char *srcdir_relative_path(const char *file)
+{
+ static const char separators[3] = { '/', SVN_PATH_LOCAL_SEPARATOR, '\0' };
+ static const char subversion[] = "subversion";
+ const apr_size_t length = sizeof(subversion) - 1;
+ apr_size_t n = strcspn(file, separators);
+
+ while (file[n])
+ {
+ ++n;
+ if (file[n])
+ {
+ if (0 == strncmp(&file[n], subversion, length)
+ && (file[n + length] == 0
+ || file[n + length] == separators[0]
+ || file[n + length] == separators[1]))
+ {
+ file = &file[n];
+ n = length;
+ }
+ else
+ {
+ n += strcspn(&file[n], separators);
+ }
+ }
+ }
+ return file;
+}
+#endif /* SVN_DEBUG */
+
/* Note: Although this is a "__" function, it was historically in the
* public ABI, so we can never change it or remove its signature, even
* though it is now only used in SVN_DEBUG mode. */
@@ -123,6 +159,7 @@ void
svn_error__locate(const char *file, long line)
{
#ifdef SVN_DEBUG
+ const char *const relfile = srcdir_relative_path(file);
# if APR_HAS_THREADS
static volatile svn_atomic_t init_status = 0;
svn_atomic__init_once_no_error(&init_status, locate_init_once, NULL);
@@ -130,7 +167,7 @@ svn_error__locate(const char *file, long line)
if (error_file_key && error_line_key)
{
apr_status_t status;
- status = apr_threadkey_private_set((char*)file, error_file_key);
+ status = apr_threadkey_private_set((char*)relfile, error_file_key);
if (status == APR_SUCCESS)
status = apr_threadkey_private_set((void*)line, error_line_key);
if (status == APR_SUCCESS)
@@ -138,7 +175,7 @@ svn_error__locate(const char *file, long line)
}
# endif /* APR_HAS_THREADS */
- error_file = file;
+ error_file = relfile;
error_line = line;
#endif /* SVN_DEBUG */
}
@@ -586,8 +623,9 @@ print_error(svn_error_t *err, FILE *stream, const
if (err->file
&& !(temp_err = svn_utf_cstring_to_utf8(&file_utf8, err->file,
err->pool)))
- svn_error_clear(svn_cmdline_fprintf(stream, err->pool,
- "%s:%ld", err->file, err->line));
+ svn_error_clear(svn_cmdline_fprintf(stream, err->pool, "...%c%s:%ld",
+ SVN_PATH_LOCAL_SEPARATOR,
+ file_utf8, err->line));
else
{
svn_error_clear(svn_cmdline_fputs(SVN_FILE_LINE_UNDEFINED,