Skip to content

Commit

Permalink
Several fixes in ad_conv_dehex()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slowfranklin committed Feb 19, 2013
1 parent 0890360 commit 01e4f40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 8 additions & 10 deletions etc/afpd/enumerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand Down
18 changes: 14 additions & 4 deletions libatalk/adouble/ad_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 01e4f40

Please sign in to comment.