From c8385d28c3ea94a88c11d7062f969ad03c881ce1 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 1 Feb 2014 18:20:52 +0100 Subject: [PATCH] Add file pathname to logmessage parse_entries: bogus eid. FR#87 --- NEWS | 1 + libatalk/adouble/ad_open.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 2c150bdf..1f7aa7dc 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,7 @@ Changes in 3.0.7 * FIX: Saving from applications like Photoshop may fail, because removing the ressource fork AppleDouble file failed. Bug #542. * FIX: macusers showed root user. Bug #495. +* UPD: Add file pathname to logmessage parse_entries: bogus eid. FR#87. Changes in 3.0.6 ================ diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index 1708d08b..92ffc885 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -387,13 +387,13 @@ static int new_ad_header(struct adouble *ad, const char *path, struct stat *stp, return 0; } -/* ------------------------------------- - read in the entries -*/ -static void parse_entries(struct adouble *ad, char *buf, uint16_t nentries) +/** + * Read an AppleDouble buffer, returns 0 on success, -1 if an entry was malformatted + **/ +static int parse_entries(struct adouble *ad, char *buf, uint16_t nentries) { uint32_t eid, len, off; - int warning = 0; + int ret = 0; /* now, read in the entry bits */ for (; nentries > 0; nentries-- ) { @@ -413,11 +413,13 @@ static void parse_entries(struct adouble *ad, char *buf, uint16_t nentries) && (off + len <= sizeof(ad->ad_data) || eid == ADEID_RFORK)) { ad->ad_eid[ eid ].ade_off = off; ad->ad_eid[ eid ].ade_len = len; - } else if (!warning) { - warning = 1; + } else if (ret == 0) { + ret = -11; LOG(log_warning, logtype_ad, "parse_entries: bogus eid: %d", eid); } } + + return ret; } /* this reads enough of the header so that we can figure out all of @@ -427,7 +429,7 @@ static void parse_entries(struct adouble *ad, char *buf, uint16_t nentries) * NOTE: we're assuming that the resource fork is kept at the end of * the file. also, mmapping won't work for the hfs fs until it * understands how to mmap header files. */ -static int ad_header_read(const char *path _U_, struct adouble *ad, const struct stat *hst) +static int ad_header_read(const char *path, struct adouble *ad, const struct stat *hst) { char *buf = ad->ad_data; uint16_t nentries; @@ -475,7 +477,10 @@ static int ad_header_read(const char *path _U_, struct adouble *ad, const struct /* figure out all of the entry offsets and lengths. if we aren't * able to read a resource fork entry, bail. */ nentries = len / AD_ENTRY_LEN; - parse_entries(ad, buf, nentries); + if (parse_entries(ad, buf, nentries) != 0) { + LOG(log_warning, logtype_ad, "ad_header_read(%s): malformed AppleDouble", + path ? fullpathname(path) : ""); + } if (!ad_getentryoff(ad, ADEID_RFORK) || (ad_getentryoff(ad, ADEID_RFORK) > sizeof(ad->ad_data)) ) { @@ -549,7 +554,7 @@ EC_CLEANUP: } /* Read an ._ file, only uses the resofork, finderinfo is taken from EA */ -static int ad_header_read_osx(const char *path _U_, struct adouble *ad, const struct stat *hst) +static int ad_header_read_osx(const char *path, struct adouble *ad, const struct stat *hst) { EC_INIT; struct adouble adosx; @@ -595,7 +600,10 @@ static int ad_header_read_osx(const char *path _U_, struct adouble *ad, const st } nentries = len / AD_ENTRY_LEN; - parse_entries(&adosx, buf, nentries); + if (parse_entries(&adosx, buf, nentries) != 0) { + LOG(log_warning, logtype_ad, "ad_header_read(%s): malformed AppleDouble", + path ? fullpathname(path) : ""); + } if (ad_getentryoff(&adosx, ADEID_RFORK) == 0 || ad_getentryoff(&adosx, ADEID_RFORK) > sizeof(ad->ad_data) @@ -662,7 +670,10 @@ static int ad_header_read_ea(const char *path, struct adouble *ad, const struct } /* Now parse entries */ - parse_entries(ad, buf + AD_HEADER_LEN, nentries); + if (parse_entries(ad, buf + AD_HEADER_LEN, nentries)) { + LOG(log_warning, logtype_ad, "ad_header_read(%s): malformed AppleDouble", + path ? fullpathname(path) : ""); + } if (nentries != ADEID_NUM_EA || !ad_entry(ad, ADEID_FINDERI) @@ -1352,7 +1363,7 @@ static int ad_open_rf_ea(const char *path, int adflags, int mode, struct adouble /* Read the adouble header */ LOG(log_debug, logtype_ad, "ad_open_rf(\"%s\"): reading adouble rfork: \"%s\"", path, rfpath); - EC_NEG1_LOG( ad_header_read_osx(NULL, ad, &st) ); + EC_NEG1_LOG( ad_header_read_osx(rfpath, ad, &st) ); } #endif -- 2.39.2