From 669793e6ca2a3cfe8773d008f54919b3849367ec Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 7 Sep 2004 14:46:21 +0000 Subject: [PATCH] fixed some crash situation with OGo bug #883 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@117 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 4 + .../NGObjWeb/NGObjWeb/WODirectAction.h | 1 - sope-appserver/NGObjWeb/Version | 2 +- sope-appserver/NGObjWeb/WOContext.m | 28 ++++--- sope-appserver/mod_ngobjweb/README | 18 +++++ sope-mime/ChangeLog | 4 + sope-mime/NGImap4/ChangeLog | 5 ++ sope-mime/NGImap4/NGImap4ResponseParser.m | 78 ++++++++++++------- sope-mime/Version | 2 +- 9 files changed, 98 insertions(+), 44 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index a155f43e..f983d9c5 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,7 @@ +2004-09-07 Helge Hess + + * WOContext.m: minor code cleanup (v4.3.28) + 2004-09-06 Helge Hess * Defaults.plist: enable watch dog per default (use WOUseWatchDog diff --git a/sope-appserver/NGObjWeb/NGObjWeb/WODirectAction.h b/sope-appserver/NGObjWeb/NGObjWeb/WODirectAction.h index d831800f..51adf20d 100644 --- a/sope-appserver/NGObjWeb/NGObjWeb/WODirectAction.h +++ b/sope-appserver/NGObjWeb/NGObjWeb/WODirectAction.h @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGObjWeb_WODirectAction_H__ #define __NGObjWeb_WODirectAction_H__ diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 03bdd30f..7f731020 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=27 +SUBMINOR_VERSION:=28 # v4.2.413 requires libSaxObjC v4.2.33 # v4.2.341 requires libNGExtensions v4.2.77 diff --git a/sope-appserver/NGObjWeb/WOContext.m b/sope-appserver/NGObjWeb/WOContext.m index f6b07745..19e1f15c 100644 --- a/sope-appserver/NGObjWeb/WOContext.m +++ b/sope-appserver/NGObjWeb/WOContext.m @@ -524,20 +524,24 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) { } - (NSURL *)applicationURL { - if (self->appURL == nil) { - NSString *s; + NSString *s; + + if (self->appURL != nil) + return self->appURL; - s = [self->request adaptorPrefix]; - if ([s length] > 0) { - s = [NSString stringWithFormat:@"%@/%@/", - s, [self->request applicationName]]; - } - else - s = [[self->request applicationName] stringByAppendingString:@"/"]; - - self->appURL = - [[NSURL URLWithString:s relativeToURL:[self serverURL]] retain]; + // TODO: we should ensure that the suffix (.woa) is in the URL + + s = [self->request adaptorPrefix]; + if ([s length] > 0) { + s = [[[s stringByAppendingString:@"/"] + stringByAppendingString:[self->request applicationName]] + stringByAppendingString:@"/"]; } + else + s = [[self->request applicationName] stringByAppendingString:@"/"]; + + self->appURL = + [[NSURL URLWithString:s relativeToURL:[self serverURL]] retain]; return self->appURL; } - (NSURL *)urlForKey:(NSString *)_key { diff --git a/sope-appserver/mod_ngobjweb/README b/sope-appserver/mod_ngobjweb/README index d33984ca..762f500d 100644 --- a/sope-appserver/mod_ngobjweb/README +++ b/sope-appserver/mod_ngobjweb/README @@ -31,6 +31,24 @@ SetHandler ngobjweb-adaptor SetAppPort 20000 +Apache on Debian SID +==================== + +Apache is not named 'httpd' on Debian, so you need to invoke make with a +parameter. + +Compilation for Apache2: + + make HTTPD=/usr/sbin/apache + +Afterwards move the build module to /usr/lib/apache/1.3/mod_ngobjweb.so and +copy the *.info file to the same directory. + +Then run: + modules-config apache enable mod_ngobjweb + +Finally create a proper OGo.conf in /etc/apache/conf.d. + Apache2 on SuSE 9.0 =================== diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index ab621d05..2c959693 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,7 @@ +2004-09-07 Helge Hess + + * NGImap4: removed some crash situations wrt OGo bug #883 (v4.3.179) + 2004-09-05 Helge Hess * fixed common.h files not to depend on libFoundation internals diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index c574af07..c16ff08d 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,3 +1,8 @@ +2004-09-07 Helge Hess + + * NGImap4ResponseParser.m: added some sanity checks for unexpected + parsing input, removes crashes as reported in OGo bug #883 (v4.3.179) + 2004-08-29 Marcus Mueller * NGImap4.xcode: new Xcode project diff --git a/sope-mime/NGImap4/NGImap4ResponseParser.m b/sope-mime/NGImap4/NGImap4ResponseParser.m index c1d38827..046a70a1 100644 --- a/sope-mime/NGImap4/NGImap4ResponseParser.m +++ b/sope-mime/NGImap4/NGImap4ResponseParser.m @@ -26,6 +26,11 @@ // TODO(hh): code is now prepared for last-exception, but currently it just // raises and may leak the exception object +@interface NGImap4ResponseParser(ParsingPrivates) +- (BOOL)_parseNumberUntaggedResponse:(NGMutableHashMap *)result_; +- (NSDictionary *)_parseBodyContent; +@end + @implementation NGImap4ResponseParser #define __la(__SELF__, __LACNT) \ @@ -43,7 +48,6 @@ static __inline__ int _la(NGImap4ResponseParser *self, unsigned _laCnt) { } static NSDictionary *_parseBody(NGImap4ResponseParser *self); -static NSDictionary *_parseBodyContent(NGImap4ResponseParser *self); static NSString *_parseBodyString(NGImap4ResponseParser *self, BOOL _convertString); static NSString *_parseBodyDecodeString(NGImap4ResponseParser *self, @@ -60,8 +64,6 @@ static void _parseUntaggedResponse(NGImap4ResponseParser *self, NGMutableHashMap *result_); static BOOL _parseByeUntaggedResponse(NGImap4ResponseParser *self, NGMutableHashMap *result_); -static BOOL _parseNumberUntaggedResponse(NGImap4ResponseParser *self, - NGMutableHashMap *result_); static NSArray *_parseFlagArray(NGImap4ResponseParser *self); static BOOL _parseFlagsUntaggedResponse(NGImap4ResponseParser *self, NGMutableHashMap *result_); @@ -306,6 +308,7 @@ static void _parseSieveRespone(NGImap4ResponseParser *self, } static NSData *_parseData(NGImap4ResponseParser *self) { + // TODO: split up method NSData *result; unsigned size; NSNumber *n; @@ -396,9 +399,9 @@ static NSData *_parseData(NGImap4ResponseParser *self) { } [stream writeBytes:tmpBuf count:tmpBufCnt]; } - if (lastChar != -1) { + if (lastChar != -1) [stream writeBytes:&lastChar count:1]; - } + [stream close]; [stream release]; stream = nil; result = [NSData dataWithContentsOfMappedFile:path]; @@ -407,14 +410,19 @@ static NSData *_parseData(NGImap4ResponseParser *self) { return result; } - { + if (size == 0) { + [self logWithFormat:@"ERROR(%s): got content size '0'!", + __PRETTY_FUNCTION__]; + return nil; + } + else { unsigned char *buf = NULL; - unsigned wasRead = 0; - char *tmpBuf; - unsigned cnt, tmpBufCnt, tmpSize; + unsigned wasRead = 0; + unsigned char *tmpBuf; + unsigned cnt, tmpBufCnt, tmpSize; - buf = malloc(sizeof(char) * size + 10); - + buf = calloc(size + 10, sizeof(char)); + while (wasRead < size) { [self->buffer la:(size - wasRead < LaSize) ? (size - wasRead) : LaSize]; @@ -424,22 +432,27 @@ static NSData *_parseData(NGImap4ResponseParser *self) { /* normalize response \r\n -> \n */ - tmpBuf = malloc(sizeof(char) * size + 10); + tmpBuf = calloc(size + 10, sizeof(char)); cnt = 0; tmpBufCnt = 0; - tmpSize = size - 1; - while (cnt < tmpSize) { - if ((buf[cnt] == '\r') && (buf[cnt+1] == '\n')) { - cnt++; - } - tmpBuf[tmpBufCnt++] = buf[cnt++]; + tmpSize = size == 0 ? 0 : size - 1; + while (tmpBufCnt < tmpSize && cnt < size) { + if ((buf[cnt] == '\r') && (buf[cnt + 1] == '\n')) + cnt++; /* skip \r */ + + tmpBuf[tmpBufCnt] = buf[cnt]; + tmpBufCnt++; + cnt++; + } + if (cnt < size) { + tmpBuf[tmpBufCnt] = buf[cnt]; + tmpBufCnt++; + cnt++; } - if (cnt < size) - tmpBuf[tmpBufCnt++] = buf[cnt++]; result = [NSData dataWithBytesNoCopy:tmpBuf length:tmpBufCnt]; - if (buf) free(buf); buf = NULL; + if (buf != NULL) free(buf); buf = NULL; return result; } } @@ -571,7 +584,7 @@ static void _parseUntaggedResponse(NGImap4ResponseParser *self, case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - if (_parseNumberUntaggedResponse(self, result_)) // la: 5 + if ([self _parseNumberUntaggedResponse:result_]) // la: 5 /* eg "* 928 FETCH ..." */ return; break; @@ -972,8 +985,7 @@ static BOOL _parseByeUntaggedResponse(NGImap4ResponseParser *self, return NO; } -static BOOL _parseNumberUntaggedResponse(NGImap4ResponseParser *self, - NGMutableHashMap *result_) { +- (BOOL)_parseNumberUntaggedResponse:(NGMutableHashMap *)result_ { NSNumber *number = nil; NSString *key = nil; @@ -1000,7 +1012,12 @@ static BOOL _parseNumberUntaggedResponse(NGImap4ResponseParser *self, key = [_parseUntil(self, ' ') lowercaseString]; if ([key hasPrefix:@"body["]) { - [fetch setObject:_parseBodyContent(self) forKey:key]; + NSDictionary *content; + + if ((content = [self _parseBodyContent]) != nil) + [fetch setObject:content forKey:key]; + else + [self logWithFormat:@"ERROR: got no body content for key: '%@'",key]; } else if ([key isEqualToString:@"body"]) { [fetch setObject:_parseBody(self) forKey:key]; @@ -1027,8 +1044,7 @@ static BOOL _parseNumberUntaggedResponse(NGImap4ResponseParser *self, else data = _parseData(self); - if (data) - [fetch setObject:data forKey:key]; + if (data != nil) [fetch setObject:data forKey:key]; } else { NSException *e; @@ -1402,9 +1418,9 @@ static NSDictionary *_parseBody(NGImap4ResponseParser *self) { return result; } -static NSDictionary *_parseBodyContent(NGImap4ResponseParser *self) { +- (NSDictionary *)_parseBodyContent { NSData *data; - + if (_la(self, 0) == '"') { NSString *str; _consume(self,1); @@ -1415,6 +1431,10 @@ static NSDictionary *_parseBodyContent(NGImap4ResponseParser *self) { else data = _parseData(self); + if (data == nil) { + [self logWithFormat:@"ERROR(%s): got no data.", __PRETTY_FUNCTION__]; + return nil; + } return [NSDictionary dictionaryWithObject:data forKey:@"data"]; } diff --git a/sope-mime/Version b/sope-mime/Version index 6db097dd..5f2383a0 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,6 +2,6 @@ MAJOR_VERSION:=4 MINOR_VERSION:=3 -SUBMINOR_VERSION:=178 +SUBMINOR_VERSION:=179 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5