Permalink
Browse files

Protect against NULL mailbox names

  • Loading branch information...
1 parent 1d4ee05 commit 33069f8df1effe7eee743149309336a4ac592fb0 @mronge mronge committed Feb 4, 2014
Showing with 46 additions and 14 deletions.
  1. +46 −14 Source/CTCoreFolder.m
View
@@ -40,6 +40,10 @@
#include <unistd.h>
+NSError* MailCoreCreateStringConvError() {
+ return MailCoreCreateError(1, @"Unable to convert folder name");
+}
+
//int imap_fetch_result_to_envelop_list(clist * fetch_result, struct mailmessage_list * env_list);
//
@@ -64,7 +68,11 @@ - (id)initWithPath:(NSString *)path inAccount:(CTCoreAccount *)account; {
myAccount = [account retain];
char buffer[MAX_PATH_SIZE];
- myFolder = mailfolder_new(storage, [self getUTF7String:buffer fromString:myPath], NULL);
+ if (![self getUTF7String:buffer fromString:myPath]) {
+ return nil;
+ }
+
+ myFolder = mailfolder_new(storage, buffer, NULL);
if (!myFolder) {
return nil;
}
@@ -85,13 +93,12 @@ - (void)dealloc {
}
-- (const char *)getUTF7String:(char *)buffer fromString:(NSString *)str {
- if (CFStringGetCString((CFStringRef)str, buffer, MAX_PATH_SIZE, kCFStringEncodingUTF7_IMAP)) {
- return buffer;
- }
- else {
- return NULL;
+- (BOOL)getUTF7String:(char *)buffer fromString:(NSString *)str {
+ if (str == nil) {
+ return NO;
}
+
+ return CFStringGetCString((CFStringRef)str, buffer, MAX_PATH_SIZE, kCFStringEncodingUTF7_IMAP);
}
@@ -134,10 +141,17 @@ - (BOOL)setPath:(NSString *)path; {
}
char newPath[MAX_PATH_SIZE];
- [self getUTF7String:newPath fromString:path];
+ if (![self getUTF7String:newPath fromString:path]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
char oldPath[MAX_PATH_SIZE];
[self getUTF7String:oldPath fromString:myPath];
+ if (![self getUTF7String:oldPath fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
err = mailimap_rename([myAccount session], oldPath, newPath);
@@ -246,7 +260,10 @@ - (BOOL)create {
int err;
char path[MAX_PATH_SIZE];
- [self getUTF7String:path fromString:myPath];
+ if (![self getUTF7String:path fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
err = mailimap_create([myAccount session], path);
if (err != MAILIMAP_NO_ERROR) {
@@ -266,7 +283,10 @@ - (BOOL)delete {
int err;
char path[MAX_PATH_SIZE];
- [self getUTF7String:path fromString:myPath];
+ if (![self getUTF7String:path fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
BOOL success = [self connect];
if (!success) {
@@ -290,7 +310,10 @@ - (BOOL)subscribe {
int err;
char path[MAX_PATH_SIZE];
- [self getUTF7String:path fromString:myPath];
+ if (![self getUTF7String:path fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
BOOL success = [self connect];
if (!success) {
@@ -310,7 +333,10 @@ - (BOOL)unsubscribe {
int err;
char path[MAX_PATH_SIZE];
- [self getUTF7String:path fromString:myPath];
+ if (![self getUTF7String:path fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
BOOL success = [self connect];
if (!success) {
@@ -832,7 +858,10 @@ - (BOOL)copyMessageWithUID:(NSUInteger)uid toPath:(NSString *)path {
}
char mbPath[MAX_PATH_SIZE];
- [self getUTF7String:mbPath fromString:path];
+ if (![self getUTF7String:mbPath fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
int err = mailsession_copy_message([self folderSession], uid, mbPath);
if (err != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromIMAPCode(err);
@@ -848,7 +877,10 @@ - (BOOL)moveMessageWithUID:(NSUInteger)uid toPath:(NSString *)path {
}
char mbPath[MAX_PATH_SIZE];
- [self getUTF7String:mbPath fromString:path];
+ if (![self getUTF7String:mbPath fromString:myPath]) {
+ self.lastError = MailCoreCreateStringConvError();
+ return NO;
+ }
int err = mailsession_move_message([self folderSession], uid, mbPath);
if (err != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromIMAPCode(err);

0 comments on commit 33069f8

Please sign in to comment.