From 01e4f40259950a534d8608e0b3e68e50fb1ca233 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Tue, 19 Feb 2013 17:35:04 +0100 Subject: [PATCH] Several fixes in ad_conv_dehex() Testing whether we need to perform dehexing was done by a simple strchr(':'), thus names only containing a single ':' would trigger dehexing even though they might not contain the relevant strings ":2e" or :2f". Also fix a ressource leak in bfindreplace() and simplify the check whether a rename took place in enumerate.c. --- etc/afpd/enumerate.c | 18 ++++++++---------- libatalk/adouble/ad_conv.c | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/etc/afpd/enumerate.c b/etc/afpd/enumerate.c index 0c3c0576..5f0e1644 100644 --- a/etc/afpd/enumerate.c +++ b/etc/afpd/enumerate.c @@ -362,16 +362,14 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, /* conversions on the fly */ const char *convname; - if (ad_convert(sd.sd_last, &s_path.st, vol, &convname) == 0 && convname) { - s_path.u_name = (char *)convname; - } - - /* Fixup CNID db if ad_convert resulted in a rename (then convname != NULL) */ - if (convname) { - s_path.id = cnid_lookup(vol->v_cdb, &s_path.st, curdir->d_did, sd.sd_last, strlen(sd.sd_last)); - if (s_path.id != CNID_INVALID) { - if (cnid_update(vol->v_cdb, s_path.id, &s_path.st, curdir->d_did, (char *)convname, strlen(convname)) != 0) - LOG(log_error, logtype_afpd, "enumerate: error updating CNID of \"%s\"", fullpathname(convname)); + if (ad_convert(sd.sd_last, &s_path.st, vol, &convname) == 0) { + if (convname) { + s_path.u_name = (char *)convname; + s_path.id = cnid_lookup(vol->v_cdb, &s_path.st, curdir->d_did, sd.sd_last, strlen(sd.sd_last)); + if (s_path.id != CNID_INVALID) { + if (cnid_update(vol->v_cdb, s_path.id, &s_path.st, curdir->d_did, (char *)convname, strlen(convname)) != 0) + LOG(log_error, logtype_afpd, "enumerate: error updating CNID of \"%s\"", fullpathname(convname)); + } } } diff --git a/libatalk/adouble/ad_conv.c b/libatalk/adouble/ad_conv.c index a9fae763..151ab9fd 100644 --- a/libatalk/adouble/ad_conv.c +++ b/libatalk/adouble/ad_conv.c @@ -201,21 +201,31 @@ static int ad_conv_dehex(const char *path, const struct stat *sp, const struct v { EC_INIT; static char buf[MAXPATHLEN]; - const char *p; int adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0; bstring newpath = NULL; + static bstring str2e = NULL; + static bstring str2f = NULL; + static bstring strdot = NULL; + static bstring strcolon = NULL; + + if (str2e == NULL) { + str2e = bfromcstr(":2e"); + str2f = bfromcstr(":2f"); + strdot = bfromcstr("."); + strcolon = bfromcstr(":"); + } LOG(log_debug, logtype_ad,"ad_conv_dehex(\"%s\"): BEGIN", fullpathname(path)); *newpathp = NULL; - if ((p = strchr(path, ':')) == NULL) + if (((strstr(path, ":2e")) == NULL) && ((strstr(path, ":2f")) == NULL) ) goto EC_CLEANUP; EC_NULL( newpath = bfromcstr(path) ); - EC_ZERO( bfindreplace(newpath, bfromcstr(":2e"), bfromcstr("."), 0) ); - EC_ZERO( bfindreplace(newpath, bfromcstr(":2f"), bfromcstr(":"), 0) ); + EC_ZERO( bfindreplace(newpath, str2e, strdot, 0) ); + EC_ZERO( bfindreplace(newpath, str2f, strcolon, 0) ); become_root(); if (adflags != ADFLAGS_DIR) -- 2.39.2