IOS-1704 Make it very clear if a blob is 0-terminated or not. IOS-1704
authorDirk Zimmermann <dz@pep.security>
Fri, 05 Jul 2019 14:10:21 +0200
branchIOS-1704
changeset 10486b93eb69aa75
parent 1047 b9068a05fbcd
child 1049 b6dd6a632e03
IOS-1704 Make it very clear if a blob is 0-terminated or not.
pEpObjCAdapter/PEPAttachment.m
pEpObjCAdapter/PEPMessageUtil.m
pEpObjCAdapterFramework/PEPAttachment.h
     1.1 --- a/pEpObjCAdapter/PEPAttachment.m	Fri Jul 05 14:10:21 2019 +0200
     1.2 +++ b/pEpObjCAdapter/PEPAttachment.m	Fri Jul 05 14:10:21 2019 +0200
     1.3 @@ -10,6 +10,12 @@
     1.4  
     1.5  #import "bloblist.h"
     1.6  
     1.7 +@interface PEPAttachment ()
     1.8 +
     1.9 +@property (nonatomic, nonnull) NSData *data;
    1.10 +
    1.11 +@end
    1.12 +
    1.13  @implementation PEPAttachment
    1.14  
    1.15  - (instancetype)initWithData:(NSData *)data
    1.16 @@ -18,13 +24,18 @@
    1.17          self.size = data.length;
    1.18  
    1.19          // 0-terminate the blob, just in case
    1.20 -        NSMutableData tmpData = [NSMutableData dataWithData:data];
    1.21 -        [tmpData appendBytes:"\0" length:1]
    1.22 +        NSMutableData *tmpData = [NSMutableData dataWithData:data];
    1.23 +        [tmpData appendBytes:"\0" length:1];
    1.24          self.data = [NSData dataWithData:tmpData];
    1.25      }
    1.26      return self;
    1.27  }
    1.28  
    1.29 +- (NSData *)dataWith0Terminator
    1.30 +{
    1.31 +    return self.data;
    1.32 +}
    1.33 +
    1.34  - (NSString *)description
    1.35  {
    1.36      NSMutableString *str =
     2.1 --- a/pEpObjCAdapter/PEPMessageUtil.m	Fri Jul 05 14:10:21 2019 +0200
     2.2 +++ b/pEpObjCAdapter/PEPMessageUtil.m	Fri Jul 05 14:10:21 2019 +0200
     2.3 @@ -111,7 +111,7 @@
     2.4      bl->release_value = (void (*) (char *)) free;
     2.5  
     2.6      for (PEPAttachment *theAttachment in array) {
     2.7 -        NSData *data = theAttachment.data;
     2.8 +        NSData *data = theAttachment.dataWith0Terminator;
     2.9          size_t size = [data length];
    2.10  
    2.11          char *buf = malloc(size);
     3.1 --- a/pEpObjCAdapterFramework/PEPAttachment.h	Fri Jul 05 14:10:21 2019 +0200
     3.2 +++ b/pEpObjCAdapterFramework/PEPAttachment.h	Fri Jul 05 14:10:21 2019 +0200
     3.3 @@ -15,7 +15,7 @@
     3.4  /**
     3.5   The blob (binary data) of this attachment, terminated by one \0.
     3.6   */
     3.7 -@property (nonatomic, nonnull) NSData *data;
     3.8 +@property (readonly, nonnull) NSData *dataWith0Terminator;
     3.9  
    3.10  /**
    3.11   The size (length in bytes) of the binary blob _without_ the trailing \0,