diff --git a/src/namspace.c b/src/namspace.c index 965fdd9..c69b13a 100644 --- a/src/namspace.c +++ b/src/namspace.c @@ -508,6 +508,77 @@ static void rmdir_from_structures(char *unname, DIR_BASE_ENTRY *dbe) } + +static char *debug_hpath_components(NW_HPATH *nwp, uint8 *pp_pathes) +/* + * Format NW_HPATH path components for debug output. + * + * The on-wire path buffer is not a NUL-terminated C string; it is a list of + * length-prefixed components. Logging it with %s can over-read into following + * packet memory and pollute unrelated client/test output files. + */ +{ + char buf[768]; + int pos = 0; + int k; + + if (!nwp || !pp_pathes || !nwp->components) + return(gettmpstr("", 0, 0)); + + for (k = 0; k < nwp->components && pos < (int)sizeof(buf) - 1; k++) { + int len = (int)*(pp_pathes++); + int i; + + if (k && pos < (int)sizeof(buf) - 1) + buf[pos++] = '/'; + + if (!len) { + if (pos < (int)sizeof(buf) - 1) buf[pos++] = '.'; + if (pos < (int)sizeof(buf) - 1) buf[pos++] = '.'; + continue; + } + + for (i = 0; i < len && pos < (int)sizeof(buf) - 1; i++) { + unsigned char c = pp_pathes[i]; + if (c < 32 || c == 127 || c == '`') + c = '?'; + buf[pos++] = (char)c; + } + pp_pathes += len; + } + + if (k < nwp->components && pos < (int)sizeof(buf) - 1) { + buf[pos++] = '/'; + if (pos < (int)sizeof(buf) - 1) buf[pos++] = '.'; + if (pos < (int)sizeof(buf) - 1) buf[pos++] = '.'; + if (pos < (int)sizeof(buf) - 1) buf[pos++] = '.'; + } + + buf[pos] = '\0'; + return(gettmpstr(buf, pos, 0)); +} + +static char *debug_hpath_component(uint8 *path, int len) +/* Format one length-prefixed NW_HPATH component for debug output. */ +{ + char buf[260]; + int i; + int pos = 0; + + if (!path || len <= 0) + return(gettmpstr("", 0, 0)); + + for (i = 0; i < len && pos < (int)sizeof(buf) - 1; i++) { + unsigned char c = path[i]; + if (c < 32 || c == 127 || c == '`') + c = '?'; + buf[pos++] = (char)c; + } + + buf[pos] = '\0'; + return(gettmpstr(buf, pos, 0)); +} + static int get_comp_pathes_size(NW_HPATH *nwp, uint8 *pp_pathes) /* returns size of path components in bytes */ { @@ -545,7 +616,7 @@ static int add_hpath_to_nwpath(N_NW_PATH *nwpath, pp_pathes+=len; XDPRINTF((5, 0, "component %2d, len=%3d, path='%s'", - k, len, gettmpstr(p, len, 0) )); + k, len, debug_hpath_component(p, len) )); if (!len) { /* this means '..' ! */ if (pp > nwpath->path) {