Simplify dynamic memory management.

Add utility routines and use them to simplify the
use of dynamically allocated memory.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
Dan Cross 2018-10-09 15:55:13 +00:00 committed by Andrew Pamment
parent 187cf02903
commit fa014f3a88
25 changed files with 330 additions and 504 deletions

View File

@ -47,7 +47,7 @@ HDRS:= bbs.h
OBJS:= inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o \
doors.o bbs_list.o chat_system.o email.o files.o settings.o \
lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o \
nodelist.o blog.o
nodelist.o blog.o util.o
WWWOBJS:= ../deps/aha/aha.o ../deps/hashids/hashids.o www.o www_email.o \
www_msgs.o www_last10.o www_blog.o www_files.o ${OBJS}

View File

@ -120,7 +120,7 @@ struct fido_addr *parse_fido_addr(const char *str) {
if (str == NULL) {
return NULL;
}
struct fido_addr *ret = (struct fido_addr *)malloc(sizeof(struct fido_addr));
struct fido_addr *ret = (struct fido_addr *)malloz(sizeof(struct fido_addr));
int c;
int state = 0;
@ -246,9 +246,8 @@ void s_putchar(char c) {
}
} else {
ic = iconv_open("UTF-8", "CP437");
inbuf = (char *)malloc(4);
outbuf = (char *)malloc(4);
memset(outbuf, 0, 4);
inbuf = (char *)malloz(4);
outbuf = (char *)malloz(4);
sprintf(inbuf, "%c", c);
inc = 1;
ouc = 4;
@ -296,8 +295,7 @@ void s_putstring(char *c) {
ic = iconv_open("UTF-8", "CP437");
inc = strlen(c);
inbuf = strdup(c);
outbuf = (char *)malloc(inc * 4);
memset(outbuf, 0, inc * 4);
outbuf = (char *)malloz(inc * 4);
ptr1 = outbuf;
ptr2 = inbuf;
ouc = inc * 4;
@ -1341,7 +1339,7 @@ char *str_replace(const char *str, const char *from, const char *to) {
retlen = orglen + (tolen - fromlen) * count;
} else
retlen = orglen;
ret = malloc(retlen + 1);
ret = malloz(retlen + 1);
if (ret == NULL) {
goto end_repl_str;
}

View File

@ -373,6 +373,14 @@ extern void load_strings();
extern char *get_string(int offset);
extern void chomp(char *string);
extern void die(const char *msg);
extern void *malloz(size_t size);
extern char *file2str(const char *path);
extern char *str5dup(const char *a, const char *b, const char *c, const char *d, const char *e);
extern char *str4dup(const char *a, const char *b, const char *c, const char *d);
extern char *str3dup(const char *a, const char *b, const char *c);
extern char *str2dup(const char *a, const char *b);
#if defined(ENABLE_WWW)
extern void www_init();
extern void *www_logger(void *cls, const char *uri, struct MHD_Connection *con);

View File

@ -212,11 +212,11 @@ void bbs_list() {
} else {
while (sqlite3_step(res) == SQLITE_ROW) {
if (entrycount == 0) {
entries = (struct bbs_list_entry_t **)malloc(sizeof(struct bbs_list_entry_t *));
entries = (struct bbs_list_entry_t **)malloz(sizeof(struct bbs_list_entry_t *));
} else {
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
}
entries[entrycount] = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
entries[entrycount] = (struct bbs_list_entry_t *)malloz(sizeof(struct bbs_list_entry_t));
entries[entrycount]->id = sqlite3_column_int(res, 0);
entries[entrycount]->bbsname = strdup(sqlite3_column_text(res, 1));
@ -255,7 +255,7 @@ void bbs_list() {
free(entries);
return;
} else if (tolower(c) == 'a') {
newentry = (struct bbs_list_entry_t *)malloc(sizeof(struct bbs_list_entry_t));
newentry = (struct bbs_list_entry_t *)malloz(sizeof(struct bbs_list_entry_t));
if (add_bbs(newentry)) {
entries = (struct bbs_list_entry_t **)realloc(entries, sizeof(struct bbs_list_entry_t *) * (entrycount + 1));
entries[entrycount] = newentry;

View File

@ -36,11 +36,11 @@ int blog_load(struct blog_entry_t ***entries) {
}
while (sqlite3_step(res) == SQLITE_ROW) {
if (blog_entry_count == 0) {
blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *));
blog_entries = (struct blog_entry_t **)malloz(sizeof(struct blog_entry_t *));
} else {
blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1));
}
blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t));
blog_entries[blog_entry_count] = (struct blog_entry_t *)malloz(sizeof(struct blog_entry_t));
blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0));
blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1));

View File

@ -253,8 +253,8 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
fti.orig_node = 0;
}
// write msg data
body = (char *)malloc(msghs->msgs[k]->msg_h->TxtLen);
JAM_ReadMsgText(jb, msghs->msgs[k]->msg_h->TxtOffset, msghs->msgs[k]->msg_h->TxtLen, (char *)body);
body = (char *)malloz(msghs->msgs[k]->msg_h->TxtLen);
JAM_ReadMsgText(jb, msghs->msgs[k]->msg_h->TxtOffset, msghs->msgs[k]->msg_h->TxtLen, body);
fwrite(body, 1, msghs->msgs[k]->msg_h->TxtLen, dat_file);
fwrite(&fti, sizeof(FTI_REC), 1, fti_file);
@ -303,9 +303,9 @@ void bwave_create_packet() {
int stin;
int sterr;
char *weekday[] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
struct stat s;
struct termios oldit;
struct termios oldot;
struct stat s;
struct tm time_tm;
time_t thetime;
FILE *mix_file;
@ -386,12 +386,10 @@ void bwave_create_packet() {
totmsgs = bwave_scan_email(area_count + 1, totmsgs, fti_file, mix_file, dat_file, &last_ptr);
s_printf(get_string(195), "Private Email", "Private Email", totmsgs);
areas = (INF_AREA_INFO **)malloc(sizeof(INF_AREA_INFO *));
areas = (INF_AREA_INFO **)malloz(sizeof(INF_AREA_INFO *));
flags = 0;
areas[area_count] = (INF_AREA_INFO *)malloc(sizeof(INF_AREA_INFO));
memset(areas[area_count], 0, sizeof(INF_AREA_INFO));
areas[area_count] = (INF_AREA_INFO *)malloz(sizeof(INF_AREA_INFO));
snprintf(areas[area_count]->areanum, 6, "%d", area_count + 1);
@ -422,9 +420,7 @@ void bwave_create_packet() {
areas = (INF_AREA_INFO **)realloc(areas, sizeof(INF_AREA_INFO *) * (area_count + 1));
flags = 0;
areas[area_count] = (INF_AREA_INFO *)malloc(sizeof(INF_AREA_INFO));
memset(areas[area_count], 0, sizeof(INF_AREA_INFO));
areas[area_count] = (INF_AREA_INFO *)malloz(sizeof(INF_AREA_INFO));
snprintf(areas[area_count]->areanum, 6, "%d", area_count + 1);
@ -534,7 +530,7 @@ void bwave_create_packet() {
dup2(bbs_stdin, STDIN_FILENO);
}
args = (char **)malloc(sizeof(char *));
args = (char **)malloz(sizeof(char *));
arg_count = 0;
args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) {
@ -793,8 +789,8 @@ void bwave_upload_reply() {
tWORD msg_attr;
struct fido_addr addr;
char *body;
struct stat s;
char *tagline;
struct stat s;
int echomail = 0;
int netmail = 0;
FILE *upl_file;
@ -871,7 +867,7 @@ void bwave_upload_reply() {
dup2(bbs_stderr, STDERR_FILENO);
dup2(bbs_stdin, STDIN_FILENO);
}
args = (char **)malloc(sizeof(char *));
args = (char **)malloz(sizeof(char *));
arg_count = 0;
args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) {
@ -934,22 +930,11 @@ void bwave_upload_reply() {
}
snprintf(msgbuffer, 1024, "%s/node%d/bwave/%s", conf.bbs_path, mynode, upl_rec.filename);
if (stat(msgbuffer, &s) != 0) {
body = file2str(msgbuffer);
if (body == NULL) {
continue;
}
body = (char *)malloc(s.st_size + 1);
msg_file = fopen(msgbuffer, "r");
if (!msg_file) {
free(body);
continue;
}
fread(body, 1, s.st_size, msg_file);
fclose(msg_file);
body[s.st_size] = '\0';
bpos = 0;
for (i = 0; i < strlen(body); i++) {
if (body[i] != '\n') {
@ -1087,20 +1072,10 @@ void bwave_upload_reply() {
snprintf(originlinebuffer, 256, "\r");
}
if (stat(msgbuffer, &s) != 0) {
body = file2str(msgbuffer);
if (body == NULL) {
continue;
}
body = (char *)malloc(s.st_size + 1 + strlen(originlinebuffer));
msg_file = fopen(msgbuffer, "r");
if (!msg_file) {
free(body);
continue;
}
fread(body, 1, s.st_size, msg_file);
fclose(msg_file);
body[s.st_size] = '\0';
strcat(body, originlinebuffer);

View File

@ -352,11 +352,11 @@ void chat_system(struct user_record *user) {
return;
}
screenbuffer = (struct character_t ***)malloc(sizeof(struct character_t **) * 23);
screenbuffer = (struct character_t ***)malloz(sizeof(struct character_t **) * 23);
for (i = 0; i < 23; i++) {
screenbuffer[i] = (struct character_t **)malloc(sizeof(struct character_t *) * 80);
screenbuffer[i] = (struct character_t **)malloz(sizeof(struct character_t *) * 80);
for (z = 0; z < 80; z++) {
screenbuffer[i][z] = (struct character_t *)malloc(sizeof(struct character_t));
screenbuffer[i][z] = (struct character_t *)malloz(sizeof(struct character_t));
screenbuffer[i][z]->c = '\0';
screenbuffer[i][z]->color = 7;
}

View File

@ -421,9 +421,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
ic = iconv_open(codepage, "UTF-8");
}
ptr1 = outbuf;
ptr2 = (char *)malloc((g + 1) * 4);
ptr2 = (char *)malloz((g + 1) * 4);
ptr2p = ptr2;
memset(ptr2, 0, (g + 1) * 4);
inc = g;
ouc = (g + 1) * 4;
@ -456,9 +455,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
ic = iconv_open("UTF-8", codepage);
}
ptr1 = outbuf;
ptr2 = (char *)malloc((g + 1) * 4);
ptr2 = (char *)malloz((g + 1) * 4);
ptr2p = ptr2;
memset(ptr2, 0, (g + 1) * 4);
inc = g;
ouc = (g + 1) * 4;
@ -525,7 +523,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
if (cwd != NULL) {
chdir(cwd);
}
args = (char **)malloc(sizeof(char *));
args = (char **)malloz(sizeof(char *));
arg_count = 0;
args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) {

View File

@ -162,12 +162,12 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
for (z = 0; z < strlen(emails[msgno]->body); z++) {
if (emails[msgno]->body[z] == '\r' || chars == 79) {
if (msg_line_count == 0) {
msg_lines = (char **)malloc(sizeof(char *));
msg_lines = (char **)malloz(sizeof(char *));
} else {
msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1));
}
msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
msg_lines[msg_line_count] = (char *)malloz(sizeof(char) * (z - start_line + 1));
if (z == start_line) {
msg_lines[msg_line_count][0] = '\0';
@ -278,8 +278,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema
snprintf(buffer, 256, "%s", emails[msgno]->subject);
}
}
subject = (char *)malloc(strlen(buffer) + 1);
strcpy(subject, buffer);
subject = strdup(buffer);
replybody = external_editor(user, user->loginname, emails[msgno]->from, emails[msgno]->body, strlen(emails[msgno]->body), emails[msgno]->from, subject, 1, 0);
if (replybody != NULL) {
@ -399,12 +398,12 @@ void list_emails(struct user_record *user) {
email_count = 0;
while (sqlite3_step(res) == SQLITE_ROW) {
if (email_count == 0) {
emails = (struct email_msg **)malloc(sizeof(struct email_msg *));
emails = (struct email_msg **)malloz(sizeof(struct email_msg *));
} else {
emails = (struct email_msg **)realloc(emails, sizeof(struct email_msg *) * (email_count + 1));
}
emails[email_count] = (struct email_msg *)malloc(sizeof(struct email_msg));
emails[email_count] = (struct email_msg *)malloz(sizeof(struct email_msg));
emails[email_count]->from = strdup((char *)sqlite3_column_text(res, 0));
emails[email_count]->subject = strdup((char *)sqlite3_column_text(res, 1));

View File

@ -370,7 +370,7 @@ char *get_file_id_diz(char *filename) {
dup2(bbs_stderr, STDERR_FILENO);
dup2(bbs_stdin, STDIN_FILENO);
}
args = (char **)malloc(sizeof(char *));
args = (char **)malloz(sizeof(char *));
arg_count = 0;
args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) {
@ -403,23 +403,17 @@ char *get_file_id_diz(char *filename) {
}
snprintf(buffer, 1024, "%s/node%d/temp/FILE_ID.DIZ", conf.bbs_path, mynode);
if (stat(buffer, &s) != 0) {
description = file2str(buffer);
if (description == NULL) {
snprintf(buffer, 1024, "%s/node%d/temp/file_id.diz", conf.bbs_path, mynode);
if (stat(buffer, &s) != 0) {
description = file2str(buffer);
if (description == NULL) {
snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode);
recursive_delete(buffer);
return NULL;
}
}
description = (char *)malloc(s.st_size + 1);
fptr = fopen(buffer, "rb");
fread(description, 1, s.st_size, fptr);
description[s.st_size] = '\0';
fclose(fptr);
bpos = 0;
len = strlen(description);
for (i = 0; i < len; i++) {
@ -510,7 +504,7 @@ int do_download(struct user_record *user, char *file) {
}
}
bpos = 1;
arguments = (char **)malloc(sizeof(char *) * (argc + 1));
arguments = (char **)malloz(sizeof(char *) * (argc + 1));
len = strlen(download_command);
for (i = 0; i < len;) {
if (download_command[i] != ' ') {
@ -618,7 +612,7 @@ int do_upload(struct user_record *user, char *final_path) {
}
}
bpos = 1;
arguments = (char **)malloc(sizeof(char *) * (argc + 1));
arguments = (char **)malloz(sizeof(char *) * (argc + 1));
len = strlen(upload_command);
for (i = 0; i < len;) {
if (upload_command[i] != ' ') {
@ -1073,11 +1067,11 @@ void do_list_files(struct file_entry **files_e, int files_c) {
}
if (match == 0) {
if (tagged_count == 0) {
tagged_files = (struct tagged_file **)malloc(sizeof(struct tagged_file *));
tagged_files = (struct tagged_file **)malloz(sizeof(struct tagged_file *));
} else {
tagged_files = (struct tagged_file **)realloc(tagged_files, sizeof(struct tagged_file *) * (tagged_count + 1));
}
tagged_files[tagged_count] = (struct tagged_file *)malloc(sizeof(struct tagged_file));
tagged_files[tagged_count] = (struct tagged_file *)malloz(sizeof(struct tagged_file));
tagged_files[tagged_count]->filename = strdup(files_e[z]->filename);
tagged_files[tagged_count]->dir = files_e[z]->dir;
tagged_files[tagged_count]->sub = files_e[z]->sub;
@ -1131,11 +1125,11 @@ void do_list_files(struct file_entry **files_e, int files_c) {
}
if (match == 0) {
if (tagged_count == 0) {
tagged_files = (struct tagged_file **)malloc(sizeof(struct tagged_file *));
tagged_files = (struct tagged_file **)malloz(sizeof(struct tagged_file *));
} else {
tagged_files = (struct tagged_file **)realloc(tagged_files, sizeof(struct tagged_file *) * (tagged_count + 1));
}
tagged_files[tagged_count] = (struct tagged_file *)malloc(sizeof(struct tagged_file));
tagged_files[tagged_count] = (struct tagged_file *)malloz(sizeof(struct tagged_file));
tagged_files[tagged_count]->filename = strdup(files_e[z]->filename);
tagged_files[tagged_count]->dir = files_e[z]->dir;
tagged_files[tagged_count]->sub = files_e[z]->sub;
@ -1178,11 +1172,11 @@ void do_list_files(struct file_entry **files_e, int files_c) {
}
if (match == 0) {
if (tagged_count == 0) {
tagged_files = (struct tagged_file **)malloc(sizeof(struct tagged_file *));
tagged_files = (struct tagged_file **)malloz(sizeof(struct tagged_file *));
} else {
tagged_files = (struct tagged_file **)realloc(tagged_files, sizeof(struct tagged_file *) * (tagged_count + 1));
}
tagged_files[tagged_count] = (struct tagged_file *)malloc(sizeof(struct tagged_file));
tagged_files[tagged_count] = (struct tagged_file *)malloz(sizeof(struct tagged_file));
tagged_files[tagged_count]->filename = strdup(files_e[z]->filename);
tagged_files[tagged_count]->dir = files_e[z]->dir;
tagged_files[tagged_count]->sub = files_e[z]->sub;
@ -1249,12 +1243,12 @@ void file_search() {
ptr = strtok(buffer, " ");
while (ptr != NULL) {
if (searchterm_count == 0) {
searchterms = (char **)malloc(sizeof(char *));
searchterms = (char **)malloz(sizeof(char *));
} else {
searchterms = (char **)realloc(searchterms, sizeof(char *) * (searchterm_count + 1));
}
searchterms[searchterm_count] = malloc(strlen(ptr) + 3);
searchterms[searchterm_count] = malloz(strlen(ptr) + 3);
sprintf(searchterms[searchterm_count], "%%%s%%", ptr);
searchterm_count++;
ptr = strtok(NULL, " ");
@ -1322,11 +1316,11 @@ void file_search() {
while (sqlite3_step(res) == SQLITE_ROW) {
if (files_c == 0) {
files_e = (struct file_entry **)malloc(sizeof(struct file_entry *));
files_e = (struct file_entry **)malloz(sizeof(struct file_entry *));
} else {
files_e = (struct file_entry **)realloc(files_e, sizeof(struct file_entry *) * (files_c + 1));
}
files_e[files_c] = (struct file_entry *)malloc(sizeof(struct file_entry));
files_e[files_c] = (struct file_entry *)malloz(sizeof(struct file_entry));
files_e[files_c]->fid = sqlite3_column_int(res, 0);
files_e[files_c]->filename = strdup((char *)sqlite3_column_text(res, 1));
files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 2));
@ -1384,11 +1378,11 @@ void file_search() {
while (sqlite3_step(res) == SQLITE_ROW) {
if (files_c == 0) {
files_e = (struct file_entry **)malloc(sizeof(struct file_entry *));
files_e = (struct file_entry **)malloz(sizeof(struct file_entry *));
} else {
files_e = (struct file_entry **)realloc(files_e, sizeof(struct file_entry *) * (files_c + 1));
}
files_e[files_c] = (struct file_entry *)malloc(sizeof(struct file_entry));
files_e[files_c] = (struct file_entry *)malloz(sizeof(struct file_entry));
files_e[files_c]->fid = sqlite3_column_int(res, 0);
files_e[files_c]->filename = strdup((char *)sqlite3_column_text(res, 1));
files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 2));
@ -1471,11 +1465,11 @@ void list_files(struct user_record *user) {
while (sqlite3_step(res) == SQLITE_ROW) {
if (files_c == 0) {
files_e = (struct file_entry **)malloc(sizeof(struct file_entry *));
files_e = (struct file_entry **)malloz(sizeof(struct file_entry *));
} else {
files_e = (struct file_entry **)realloc(files_e, sizeof(struct file_entry *) * (files_c + 1));
}
files_e[files_c] = (struct file_entry *)malloc(sizeof(struct file_entry));
files_e[files_c] = (struct file_entry *)malloz(sizeof(struct file_entry));
files_e[files_c]->fid = sqlite3_column_int(res, 0);
files_e[files_c]->filename = strdup((char *)sqlite3_column_text(res, 1));
files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 2));
@ -1514,12 +1508,12 @@ void choose_subdir() {
for (i = 0; i < conf.file_directories[gUser->cur_file_dir]->file_sub_count; i++) {
if (conf.file_directories[gUser->cur_file_dir]->file_subs[i]->download_sec_level <= gUser->sec_level) {
if (list_tmp == 0) {
sub_tmp = (struct subdir_tmp_t **)malloc(sizeof(struct subdir_tmp_t *));
sub_tmp = (struct subdir_tmp_t **)malloz(sizeof(struct subdir_tmp_t *));
} else {
sub_tmp = (struct subdir_tmp_t **)realloc(sub_tmp, sizeof(struct subdir_tmp_t *) * (list_tmp + 1));
}
sub_tmp[list_tmp] = (struct subdir_tmp_t *)malloc(sizeof(struct subdir_tmp_t));
sub_tmp[list_tmp] = (struct subdir_tmp_t *)malloz(sizeof(struct subdir_tmp_t));
sub_tmp[list_tmp]->sub = conf.file_directories[gUser->cur_file_dir]->file_subs[i];
sub_tmp[list_tmp]->index = i;
list_tmp++;
@ -1652,12 +1646,12 @@ void choose_directory() {
for (i = 0; i < conf.file_directory_count; i++) {
if (conf.file_directories[i]->sec_level <= gUser->sec_level) {
if (list_tmp == 0) {
dir_tmp = (struct dir_tmp_t **)malloc(sizeof(struct dir_tmp_t *));
dir_tmp = (struct dir_tmp_t **)malloz(sizeof(struct dir_tmp_t *));
} else {
dir_tmp = (struct dir_tmp_t **)realloc(dir_tmp, sizeof(struct dir_tmp_t *) * (list_tmp + 1));
}
dir_tmp[list_tmp] = (struct dir_tmp_t *)malloc(sizeof(struct dir_tmp_t));
dir_tmp[list_tmp] = (struct dir_tmp_t *)malloz(sizeof(struct dir_tmp_t));
dir_tmp[list_tmp]->dir = conf.file_directories[i];
dir_tmp[list_tmp]->index = i;
list_tmp++;

View File

@ -266,19 +266,11 @@ int l_readMessageHdr(lua_State *L) {
} else {
for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(subject, 0, jsp->Fields[z]->DatLen + 1);
memcpy(subject, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) {
sender = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(sender, 0, jsp->Fields[z]->DatLen + 1);
memcpy(sender, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) {
recipient = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(recipient, 0, jsp->Fields[z]->DatLen + 1);
memcpy(recipient, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) {
sender = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) {
recipient = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
}
JAM_DelSubPacket(jsp);
@ -337,7 +329,7 @@ int l_readMessage(lua_State *L) {
free(jb);
body = strdup("No Message");
} else {
body = (char *)malloc(jmh.TxtLen + 1);
body = (char *)malloz(jmh.TxtLen + 1);
JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body);
body[jmh.TxtLen] = '\0';
@ -522,7 +514,7 @@ int l_postMessage(lua_State *L) {
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline);
}
msg = (char *)malloc(strlen(body) + 2 + strlen(buffer));
msg = (char *)malloz(strlen(body) + 2 + strlen(buffer));
j = 0;
@ -531,8 +523,8 @@ int l_postMessage(lua_State *L) {
continue;
}
msg[j++] = body[i];
msg[j] = '\0';
}
msg[j] = '\0';
strcat(msg, buffer);

View File

@ -143,8 +143,7 @@ int msg_is_to(struct user_record *user, char *addressed_to, char *address, int t
int j;
int magi_dest;
if (rn) {
myname = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2);
sprintf(myname, "%s %s", user->firstname, user->lastname);
myname = str3dup(user->firstname, " ", user->lastname);
} else {
myname = strdup(user->loginname);
}
@ -190,8 +189,7 @@ int msg_is_from(struct user_record *user, char *addressed_from, char *address, i
int magi_orig;
if (rn) {
myname = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2);
sprintf(myname, "%s %s", user->firstname, user->lastname);
myname = str3dup(user->firstname, " ", user->lastname);
} else {
myname = strdup(user->loginname);
}
@ -254,7 +252,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
JAM_ReadMBHeader(jb, &jbh);
if (jbh.ActiveMsgs > 0) {
msghs = (struct msg_headers *)malloc(sizeof(struct msg_headers));
msghs = (struct msg_headers *)malloz(sizeof(struct msg_headers));
msghs->msg_count = 0;
k = 0;
for (i = 0; k < jbh.ActiveMsgs; i++) {
@ -271,10 +269,10 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
continue;
}
jamm = (struct jam_msg *)malloc(sizeof(struct jam_msg));
jamm = (struct jam_msg *)malloz(sizeof(struct jam_msg));
jamm->msg_no = i;
jamm->msg_h = (s_JamMsgHeader *)malloc(sizeof(s_JamMsgHeader));
jamm->msg_h = (s_JamMsgHeader *)malloz(sizeof(s_JamMsgHeader));
memcpy(jamm->msg_h, &jmh, sizeof(s_JamMsgHeader));
jamm->from = NULL;
jamm->to = NULL;
@ -286,39 +284,19 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
jamm->subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->subject, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->subject, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) {
jamm->from = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->from, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->from, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) {
jamm->to = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->to, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->to, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) {
jamm->daddress = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->daddress, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->daddress, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) {
jamm->oaddress = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->oaddress, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->oaddress, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
jamm->msgid = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->msgid, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->msgid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) {
jamm->replyid = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(jamm->replyid, 0, jsp->Fields[z]->DatLen + 1);
memcpy(jamm->replyid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
jamm->subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) {
jamm->from = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) {
jamm->to = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) {
jamm->daddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) {
jamm->oaddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
jamm->msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) {
jamm->replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
}
JAM_DelSubPacket(jsp);
@ -397,7 +375,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
}
if (msghs->msg_count == 0) {
msghs->msgs = (struct jam_msg **)malloc(sizeof(struct jam_msg *));
msghs->msgs = (struct jam_msg **)malloz(sizeof(struct jam_msg *));
} else {
msghs->msgs = (struct jam_msg **)realloc(msghs->msgs, sizeof(struct jam_msg *) * (msghs->msg_count + 1));
}
@ -511,7 +489,7 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot
while (len > 0) {
totlen += len;
if (body == NULL) {
body = (char *)malloc(totlen + 1);
body = (char *)malloz(totlen + 1);
} else {
body = (char *)realloc(body, totlen + 1);
}
@ -556,12 +534,12 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot
snprintf(buffer, 256, "\r");
}
if (user->autosig) {
body2 = (char *)malloc(totlen + 3 + strlen(buffer) + strlen(user->signature));
body2 = (char *)malloz(totlen + 3 + strlen(buffer) + strlen(user->signature));
} else {
body2 = (char *)malloc(totlen + 2 + strlen(buffer));
body2 = (char *)malloz(totlen + 2 + strlen(buffer));
}
} else {
body2 = (char *)malloc(totlen + 1);
body2 = (char *)malloz(totlen + 1);
}
j = 0;
@ -616,12 +594,12 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in
for (i = 0; i < quotelen; i++) {
if (quote[i] == '\r' || lineat == 67) {
if (quotelines == 0) {
quotecontent = (char **)malloc(sizeof(char *));
quotecontent = (char **)malloz(sizeof(char *));
} else {
quotecontent = (char **)realloc(quotecontent, sizeof(char *) * (quotelines + 1));
}
quotecontent[quotelines] = (char *)malloc(strlen(linebuffer) + 4);
quotecontent[quotelines] = (char *)malloz(strlen(linebuffer) + 4);
sprintf(quotecontent[quotelines], "%c> %s", from[0], linebuffer);
quotelines++;
lineat = 0;
@ -704,8 +682,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in
size += 1;
}
msg = (char *)malloc(size);
memset(msg, 0, size);
msg = (char *)malloz(size);
for (i = 0; i < lines; i++) {
strcat(msg, content[i]);
strcat(msg, "\r");
@ -773,7 +750,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in
for (i = qfrom; i <= qto; i++) {
if (lines == 0) {
content = (char **)malloc(sizeof(char *));
content = (char **)malloz(sizeof(char *));
} else {
content = (char **)realloc(content, sizeof(char *) * (lines + 1));
}
@ -866,7 +843,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in
}
} else {
if (lines == 0) {
content = (char **)malloc(sizeof(char *));
content = (char **)malloz(sizeof(char *));
} else {
content = (char **)realloc(content, sizeof(char *) * (lines + 1));
}
@ -1055,11 +1032,11 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) {
}
}
fake_screen = (struct character_t ***)malloc(sizeof(struct character_t **) * line_count);
fake_screen = (struct character_t ***)malloz(sizeof(struct character_t **) * line_count);
for (i = 0; i < line_count; i++) {
fake_screen[i] = (struct character_t **)malloc(sizeof(struct character_t *) * 80);
fake_screen[i] = (struct character_t **)malloz(sizeof(struct character_t *) * 80);
for (j = 0; j < 80; j++) {
fake_screen[i][j] = (struct character_t *)malloc(sizeof(struct character_t));
fake_screen[i][j] = (struct character_t *)malloz(sizeof(struct character_t));
fake_screen[i][j]->c = ' ';
fake_screen[i][j]->fg = fg;
fake_screen[i][j]->bg = bg;
@ -1376,7 +1353,7 @@ void unmangle_ansi(char *body, int len, char **body_out, int *body_len) {
out_max = 256;
out_len = 0;
out = (char *)malloc(256);
out = (char *)malloz(256);
for (i = 0; i < line_count; i++) {
buf_at = 0;
@ -1585,7 +1562,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
s_printf(get_string(110), (msghs->msgs[mailno]->msg_h->Attribute & JAM_MSG_SENT ? "SENT" : ""), (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[mailno]->msg_h->MsgNum) ? "FLAGGED" : ""));
s_printf(get_string(111));
body = (char *)malloc(msghs->msgs[mailno]->msg_h->TxtLen);
body = (char *)malloz(msghs->msgs[mailno]->msg_h->TxtLen);
JAM_ReadMsgText(jb, msghs->msgs[mailno]->msg_h->TxtOffset, msghs->msgs[mailno]->msg_h->TxtLen, (char *)body);
if (!newscan) {
@ -1609,12 +1586,12 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
for (z = 0; z < z2; z++) {
if (body[z] == '\r' || chars == 80) {
if (msg_line_count == 0) {
msg_lines = (char **)malloc(sizeof(char *));
msg_lines = (char **)malloz(sizeof(char *));
} else {
msg_lines = (char **)realloc(msg_lines, sizeof(char *) * (msg_line_count + 1));
}
msg_lines[msg_line_count] = (char *)malloc(sizeof(char) * (z - start_line + 1));
msg_lines[msg_line_count] = (char *)malloz(sizeof(char) * (z - start_line + 1));
if (z == start_line) {
msg_lines[msg_line_count][0] = '\0';
@ -1723,8 +1700,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
snprintf(buffer, 256, "%s", msghs->msgs[mailno]->subject);
}
}
subject = (char *)malloc(strlen(buffer) + 1);
strcpy(subject, buffer);
subject = strdup(buffer);
s_printf(get_string(114));
s_readstring_inject(buffer, 32, msghs->msgs[mailno]->from);
@ -1740,15 +1716,13 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
strcpy(buffer, msghs->msgs[mailno]->from);
}
if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) {
from = (char *)malloc(strlen(user->loginname) + 1);
strcpy(from, user->loginname);
from = strdup(user->loginname);
} else {
from = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2);
sprintf(from, "%s %s", user->firstname, user->lastname);
from = str3dup(user->firstname, " ", user->lastname);
}
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) {
free(to);
to = (char *)malloc(4);
to = (char *)malloz(4);
strcpy(to, "ALL");
}
replybody = external_editor(user, to, from, body, z2, msghs->msgs[mailno]->from, subject, 0, 0);
@ -2221,8 +2195,7 @@ void post_message(struct user_record *user) {
if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) {
from = strdup(user->loginname);
} else {
from = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2);
sprintf(from, "%s %s", user->firstname, user->lastname);
from = str3dup(user->firstname, " ", user->lastname);
}
msg = external_editor(user, to, from, NULL, 0, NULL, subject, 0, 0);
@ -2757,12 +2730,12 @@ void choose_conference() {
for (i = 0; i < conf.mail_conference_count; i++) {
if (conf.mail_conferences[i]->sec_level <= gUser->sec_level) {
if (list_tmp == 0) {
conf_tmp = (struct conf_tmp_t **)malloc(sizeof(struct conf_tmp_t *));
conf_tmp = (struct conf_tmp_t **)malloz(sizeof(struct conf_tmp_t *));
} else {
conf_tmp = (struct conf_tmp_t **)realloc(conf_tmp, sizeof(struct conf_tmp_t *) * (list_tmp + 1));
}
conf_tmp[list_tmp] = (struct conf_tmp_t *)malloc(sizeof(struct conf_tmp_t));
conf_tmp[list_tmp] = (struct conf_tmp_t *)malloz(sizeof(struct conf_tmp_t));
conf_tmp[list_tmp]->conference = conf.mail_conferences[i];
conf_tmp[list_tmp]->index = i;
list_tmp++;
@ -2903,12 +2876,12 @@ void choose_area() {
for (i = 0; i < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; i++) {
if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->read_sec_level <= gUser->sec_level) {
if (list_tmp == 0) {
area_tmp = (struct area_tmp_t **)malloc(sizeof(struct area_tmp_t *));
area_tmp = (struct area_tmp_t **)malloz(sizeof(struct area_tmp_t *));
} else {
area_tmp = (struct area_tmp_t **)realloc(area_tmp, sizeof(struct area_tmp_t *) * (list_tmp + 1));
}
area_tmp[list_tmp] = (struct area_tmp_t *)malloc(sizeof(struct area_tmp_t));
area_tmp[list_tmp] = (struct area_tmp_t *)malloz(sizeof(struct area_tmp_t));
area_tmp[list_tmp]->area = conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i];
area_tmp[list_tmp]->index = i;
list_tmp++;

View File

@ -116,12 +116,12 @@ static int protocol_config_handler(void *user, const char *section, const char *
}
if (conf->protocol_count == 0) {
conf->protocols = (struct protocol **)malloc(sizeof(struct protocol *));
conf->protocols = (struct protocol **)malloz(sizeof(struct protocol *));
} else {
conf->protocols = (struct protocol **)realloc(conf->protocols, sizeof(struct protocol *) * (conf->protocol_count + 1));
}
conf->protocols[conf->protocol_count] = (struct protocol *)malloc(sizeof(struct protocol));
conf->protocols[conf->protocol_count] = (struct protocol *)malloz(sizeof(struct protocol));
conf->protocols[conf->protocol_count]->name = strdup(section);
conf->protocols[conf->protocol_count]->internal_zmodem = 0;
@ -176,12 +176,12 @@ static int archiver_config_handler(void *user, const char *section, const char *
}
if (conf->archiver_count == 0) {
conf->archivers = (struct archiver **)malloc(sizeof(struct archiver *));
conf->archivers = (struct archiver **)malloz(sizeof(struct archiver *));
} else {
conf->archivers = (struct archiver **)realloc(conf->archivers, sizeof(struct archiver *) * (conf->archiver_count + 1));
}
conf->archivers[conf->archiver_count] = (struct archiver *)malloc(sizeof(struct archiver));
conf->archivers[conf->archiver_count] = (struct archiver *)malloz(sizeof(struct archiver));
conf->archivers[conf->archiver_count]->name = strdup(section);
@ -221,12 +221,12 @@ static int door_config_handler(void *user, const char *section, const char *name
}
if (conf->door_count == 0) {
conf->doors = (struct door_config **)malloc(sizeof(struct door_config *));
conf->doors = (struct door_config **)malloz(sizeof(struct door_config *));
} else {
conf->doors = (struct door_config **)realloc(conf->doors, sizeof(struct door_config *) * (conf->door_count + 1));
}
conf->doors[conf->door_count] = (struct door_config *)malloc(sizeof(struct door_config));
conf->doors[conf->door_count] = (struct door_config *)malloz(sizeof(struct door_config));
conf->doors[conf->door_count]->name = strdup(section);
conf->doors[conf->door_count]->codepage = NULL;
@ -279,12 +279,12 @@ static int file_sub_handler(void *user, const char *section, const char *name,
}
}
if (fd->file_sub_count == 0) {
fd->file_subs = (struct file_sub **)malloc(sizeof(struct file_sub *));
fd->file_subs = (struct file_sub **)malloz(sizeof(struct file_sub *));
} else {
fd->file_subs = (struct file_sub **)realloc(fd->file_subs, sizeof(struct file_sub *) * (fd->file_sub_count + 1));
}
fd->file_subs[fd->file_sub_count] = (struct file_sub *)malloc(sizeof(struct file_sub));
fd->file_subs[fd->file_sub_count] = (struct file_sub *)malloz(sizeof(struct file_sub));
fd->file_subs[fd->file_sub_count]->name = strdup(section);
if (strcasecmp(name, "upload sec level") == 0) {
@ -372,12 +372,12 @@ static int mail_area_handler(void *user, const char *section, const char *name,
}
}
if (mc->mail_area_count == 0) {
mc->mail_areas = (struct mail_area **)malloc(sizeof(struct mail_area *));
mc->mail_areas = (struct mail_area **)malloz(sizeof(struct mail_area *));
} else {
mc->mail_areas = (struct mail_area **)realloc(mc->mail_areas, sizeof(struct mail_area *) * (mc->mail_area_count + 1));
}
mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloc(sizeof(struct mail_area));
mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloz(sizeof(struct mail_area));
mc->mail_areas[mc->mail_area_count]->qwkname = NULL;
@ -443,8 +443,7 @@ static int handler(void *user, const char *section, const char *name,
if (value[strlen(value) - 1] == '/') {
conf->www_url = strdup(value);
} else {
conf->www_url = (char *)malloc(strlen(value) + 2);
sprintf(conf->www_url, "%s/", value);
conf->www_url = str2dup(value, "/");
}
} else if (strcasecmp(name, "ssh port") == 0) {
conf->ssh_port = atoi(value);
@ -566,12 +565,12 @@ static int handler(void *user, const char *section, const char *name,
}
} else if (strcasecmp(section, "mail conferences") == 0) {
if (conf->mail_conference_count == 0) {
conf->mail_conferences = (struct mail_conference **)malloc(sizeof(struct mail_conference *));
conf->mail_conferences = (struct mail_conference **)malloz(sizeof(struct mail_conference *));
} else {
conf->mail_conferences = (struct mail_conference **)realloc(conf->mail_conferences, sizeof(struct mail_conference *) * (conf->mail_conference_count + 1));
}
conf->mail_conferences[conf->mail_conference_count] = (struct mail_conference *)malloc(sizeof(struct mail_conference));
conf->mail_conferences[conf->mail_conference_count] = (struct mail_conference *)malloz(sizeof(struct mail_conference));
conf->mail_conferences[conf->mail_conference_count]->name = strdup(name);
conf->mail_conferences[conf->mail_conference_count]->path = strdup(value);
conf->mail_conferences[conf->mail_conference_count]->tagline = NULL;
@ -582,12 +581,12 @@ static int handler(void *user, const char *section, const char *name,
conf->mail_conference_count++;
} else if (strcasecmp(section, "file directories") == 0) {
if (conf->file_directory_count == 0) {
conf->file_directories = (struct file_directory **)malloc(sizeof(struct file_directory *));
conf->file_directories = (struct file_directory **)malloz(sizeof(struct file_directory *));
} else {
conf->file_directories = (struct file_directory **)realloc(conf->file_directories, sizeof(struct file_directory *) * (conf->file_directory_count + 1));
}
conf->file_directories[conf->file_directory_count] = (struct file_directory *)malloc(sizeof(struct file_directory));
conf->file_directories[conf->file_directory_count] = (struct file_directory *)malloz(sizeof(struct file_directory));
conf->file_directories[conf->file_directory_count]->name = strdup(name);
conf->file_directories[conf->file_directory_count]->path = strdup(value);
conf->file_directories[conf->file_directory_count]->file_sub_count = 0;
@ -595,12 +594,12 @@ static int handler(void *user, const char *section, const char *name,
conf->file_directory_count++;
} else if (strcasecmp(section, "text files") == 0) {
if (conf->text_file_count == 0) {
conf->text_files = (struct text_file **)malloc(sizeof(struct text_file *));
conf->text_files = (struct text_file **)malloz(sizeof(struct text_file *));
} else {
conf->text_files = (struct text_file **)realloc(conf->text_files, sizeof(struct text_file *) * (conf->text_file_count + 1));
}
conf->text_files[conf->text_file_count] = (struct text_file *)malloc(sizeof(struct text_file));
conf->text_files[conf->text_file_count] = (struct text_file *)malloz(sizeof(struct text_file));
conf->text_files[conf->text_file_count]->name = strdup(name);
conf->text_files[conf->text_file_count]->path = strdup(value);
conf->text_file_count++;
@ -845,7 +844,7 @@ void serverssh(int port, int ipv6) {
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
if (i == MAP_MISSING) {
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard = (struct ip_address_guard *)malloz(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_UNKNOWN;
ip_guard->last_connection = time(NULL);
ip_guard->connection_count = 1;
@ -1026,7 +1025,7 @@ void server(int port, int ipv6) {
}
}
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard = (struct ip_address_guard *)malloz(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_WHITELISTED;
hashmap_put(ip_guard_map, strdup(buffer), ip_guard);
@ -1049,7 +1048,7 @@ void server(int port, int ipv6) {
}
}
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard = (struct ip_address_guard *)malloz(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_BLACKLISTED;
hashmap_put(ip_guard_map, strdup(buffer), ip_guard);
@ -1204,7 +1203,7 @@ void server(int port, int ipv6) {
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
if (i == MAP_MISSING) {
ip_guard = (struct ip_address_guard *)malloc(sizeof(struct ip_address_guard));
ip_guard = (struct ip_address_guard *)malloz(sizeof(struct ip_address_guard));
ip_guard->status = IP_STATUS_UNKNOWN;
ip_guard->last_connection = time(NULL);
ip_guard->connection_count = 1;

View File

@ -120,11 +120,11 @@ int menu_system(char *menufile) {
if (strncasecmp(buffer, "HOTKEY", 6) == 0) {
menu_items++;
if (menu_items == 1) {
menu = (struct menu_item **)malloc(sizeof(struct menu_item *));
menu = (struct menu_item **)malloz(sizeof(struct menu_item *));
} else {
menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items));
}
menu[menu_items - 1] = (struct menu_item *)malloc(sizeof(struct menu_item));
menu[menu_items - 1] = (struct menu_item *)malloz(sizeof(struct menu_item));
menu[menu_items - 1]->hotkey = buffer[7];
menu[menu_items - 1]->command = NULL;
menu[menu_items - 1]->data = NULL;
@ -132,8 +132,8 @@ int menu_system(char *menufile) {
menu[menu_items - 1]->seclevel = 0;
} else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) {
if (menu[menu_items - 1]->command_count == 0) {
menu[menu_items - 1]->command = (int *)malloc(sizeof(int));
menu[menu_items - 1]->data = (char **)malloc(sizeof(char *));
menu[menu_items - 1]->command = (int *)malloz(sizeof(int));
menu[menu_items - 1]->data = (char **)malloz(sizeof(char *));
} else {
menu[menu_items - 1]->command = (int *)realloc(menu[menu_items - 1]->command, sizeof(int) * (menu[menu_items - 1]->command_count + 1));
menu[menu_items - 1]->data = (char **)realloc(menu[menu_items - 1]->data, sizeof(char *) * (menu[menu_items - 1]->command_count + 1));

View File

@ -97,11 +97,11 @@ void nl_browser() {
while (sqlite3_step(res) == SQLITE_ROW) {
if (entry_count == 0) {
entries = (struct nl_temp **)malloc(sizeof(struct nl_temp *));
entries = (struct nl_temp **)malloz(sizeof(struct nl_temp *));
} else {
entries = (struct nl_temp **)realloc(entries, sizeof(struct nl_temp *) * (entry_count + 1));
}
entries[entry_count] = (struct nl_temp *)malloc(sizeof(struct nl_temp));
entries[entry_count] = (struct nl_temp *)malloz(sizeof(struct nl_temp));
entries[entry_count]->address = strdup(sqlite3_column_text(res, 0));
entries[entry_count]->location = strdup(sqlite3_column_text(res, 1));

View File

@ -78,8 +78,7 @@ void settings_menu(struct user_record *user) {
s_printf(get_string(160));
s_readstring(buffer, 32);
free(user->location);
user->location = (char *)malloc(strlen(buffer) + 1);
strcpy(user->location, buffer);
user->location = strdup(buffer);
save_user(user);
} break;
case 'a': {

View File

@ -16,7 +16,7 @@ void chomp(char *string) {
}
char *parse_newlines(char *string) {
char *newstring = (char *)malloc(strlen(string) + 1);
char *newstring = (char *)malloz(strlen(string) + 1);
int pos = 0;
int i;
for (i = 0; i < strlen(string); i++) {
@ -71,7 +71,7 @@ void load_strings() {
while (!feof(fptr)) {
chomp(buffer);
if (string_count == 0) {
strings = (char **)malloc(sizeof(char *));
strings = (char **)malloz(sizeof(char *));
} else {
strings = (char **)realloc(strings, sizeof(char *) * (string_count + 1));
}

View File

@ -16,18 +16,13 @@ extern struct bbs_config conf;
extern struct user_record *gUser;
char *hash_sha256(char *pass, char *salt) {
char *buffer = (char *)malloc(strlen(pass) + strlen(salt) + 1);
char *buffer = NULL;
char *shash = NULL;
unsigned char hash[EVP_MAX_MD_SIZE];
unsigned int length_of_hash = 0;
int i;
if (!buffer) {
dolog("Out of memory!");
exit(-1);
}
sprintf(buffer, "%s%s", pass, salt);
buffer = str2dup(pass, salt);
EVP_MD_CTX *context = EVP_MD_CTX_new();
@ -36,7 +31,7 @@ char *hash_sha256(char *pass, char *salt) {
if (EVP_DigestUpdate(context, buffer, strlen(buffer))) {
if (EVP_DigestFinal_ex(context, hash, &length_of_hash)) {
shash = (char *)malloc(length_of_hash * 2 + 1);
shash = (char *)malloz(length_of_hash * 2 + 1);
for (i = 0; i < length_of_hash; i++) {
sprintf(shash + (i * 2), "%02x", (int)hash[i]);
}
@ -58,7 +53,7 @@ void gen_salt(char **s) {
FILE *fptr;
int i;
char c;
*s = (char *)malloc(11);
*s = (char *)malloz(11);
char *salt = *s;
@ -482,7 +477,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
int step = sqlite3_step(res);
if (step == SQLITE_ROW) {
user = (struct user_record *)malloc(sizeof(struct user_record));
user = (struct user_record *)malloz(sizeof(struct user_record));
user->id = sqlite3_column_int(res, 0);
user->loginname = strdup((char *)sqlite3_column_text(res, 1));
user->password = strdup((char *)sqlite3_column_text(res, 2));
@ -534,7 +529,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
sqlite3_finalize(res);
sqlite3_close(db);
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
user->sec_info = (struct sec_level_t *)malloz(sizeof(struct sec_level_t));
snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level);
if (ini_parse(buffer, secLevel, user->sec_info) < 0) {
@ -696,7 +691,7 @@ struct user_record *new_user() {
int i;
int fullnameok = 0;
user = (struct user_record *)malloc(sizeof(struct user_record));
user = (struct user_record *)malloz(sizeof(struct user_record));
s_printf("\r\n\r\n");
s_displayansi("newuser");
@ -856,7 +851,7 @@ struct user_record *new_user() {
} while (!done);
user->sec_level = conf.newuserlvl;
user->bwavepktno = 0;
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
user->sec_info = (struct sec_level_t *)malloz(sizeof(struct sec_level_t));
snprintf(buffer, PATH_MAX, "%s/config/s%d.ini", conf.bbs_path, user->sec_level);
if (ini_parse(buffer, secLevel, user->sec_info) < 0) {

88
src/util.c Normal file
View File

@ -0,0 +1,88 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "bbs.h"
void die(const char *msg) {
dolog(msg);
exit(-1);
}
void *malloz(size_t size) {
void *p = malloc(size);
if (p == NULL)
die("Out of memory");
memset(p, 0, size);
return p;
}
char *file2str(const char *path) {
struct stat s;
int fd;
memset(&s, 0, sizeof(s));
if (stat(path, &s) < 0)
return NULL;
if (!S_ISREG(s.st_mode))
return NULL;
fd = open(path, O_RDONLY);
if (fd < 0)
return NULL;
char *contents = malloz(s.st_size + 1);
if (read(fd, contents, s.st_size) != s.st_size) {
free(contents);
close(fd);
return NULL;
}
close(fd);
contents[s.st_size] = '\0';
return contents;
}
char *str5dup(const char *a, const char *b, const char *c, const char *d, const char *e) {
char *p;
size_t alen, blen, clen, dlen, elen;
if (a == NULL)
a = "";
if (b == NULL)
b = "";
if (c == NULL)
c = "";
if (d == NULL)
d = "";
if (e == NULL)
e = "";
alen = strlen(a);
blen = strlen(b);
clen = strlen(c);
dlen = strlen(d);
elen = strlen(e);
p = malloz(alen + blen + clen + dlen + elen + 1);
memmove(p, a, alen);
memmove(p + alen, b, blen);
memmove(p + alen + blen, c, clen);
memmove(p + alen + blen + clen, d, dlen);
memmove(p + alen + blen + clen + dlen, e, elen);
return p;
}
char *str4dup(const char *a, const char *b, const char *c, const char *d) {
return str5dup(a, b, c, d, "");
}
char *str3dup(const char *a, const char *b, const char *c) {
return str5dup(a, b, c, "", "");
}
char *str2dup(const char *a, const char *b) {
return str5dup(a, b, "", "", "");
}

248
src/www.c
View File

@ -44,10 +44,10 @@ void *www_logger(void *cls, const char *uri, struct MHD_Connection *con) {
struct sockaddr *so = (struct sockaddr *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr;
char *ipaddr;
if (so->sa_family == AF_INET) {
ipaddr = (char *)malloc(INET_ADDRSTRLEN + 1);
ipaddr = (char *)malloz(INET_ADDRSTRLEN + 1);
inet_ntop(AF_INET, &((struct sockaddr_in *)so)->sin_addr, ipaddr, INET_ADDRSTRLEN);
} else if (so->sa_family == AF_INET6) {
ipaddr = (char *)malloc(INET6_ADDRSTRLEN + 1);
ipaddr = (char *)malloz(INET6_ADDRSTRLEN + 1);
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)so)->sin6_addr, ipaddr, INET6_ADDRSTRLEN);
}
dolog_www(ipaddr, "%s", uri);
@ -114,8 +114,8 @@ static int iterate_post(void *coninfo_cls, enum MHD_ValueKind kind, const char *
}
if (con_info->count == 0) {
con_info->keys = (char **)malloc(sizeof(char *));
con_info->values = (char **)malloc(sizeof(char *));
con_info->keys = (char **)malloz(sizeof(char *));
con_info->values = (char **)malloz(sizeof(char *));
} else {
con_info->keys = (char **)realloc(con_info->keys, sizeof(char *) * (con_info->count + 1));
con_info->values = (char **)realloc(con_info->values, sizeof(char *) * (con_info->count + 1));
@ -153,12 +153,12 @@ void www_init() {
if (buffer[i] == ' ') {
buffer[i] = '\0';
if (mime_types_count == 0) {
mime_types = (struct mime_type **)malloc(sizeof(struct mime_type *));
mime_types = (struct mime_type **)malloz(sizeof(struct mime_type *));
} else {
mime_types = (struct mime_type **)realloc(mime_types, sizeof(struct mime_type *) * (mime_types_count + 1));
}
mime_types[mime_types_count] = (struct mime_type *)malloc(sizeof(struct mime_type));
mime_types[mime_types_count] = (struct mime_type *)malloz(sizeof(struct mime_type));
mime_types[mime_types_count]->mime = strdup(buffer);
mime_types[mime_types_count]->ext = strdup(&buffer[i + 1]);
@ -193,7 +193,6 @@ char *www_get_mime_type(const char *extension) {
int www_401(char *header, char *footer, struct MHD_Connection *connection) {
char buffer[PATH_MAX];
char *page, *page_tmp;
struct stat s;
char *whole_page;
struct MHD_Response *response;
int ret;
@ -201,38 +200,19 @@ int www_401(char *header, char *footer, struct MHD_Connection *connection) {
snprintf(buffer, PATH_MAX, "%s/401.tpl", conf.www_path);
page_tmp = NULL;
page_tmp = file2str(buffer);
if (stat(buffer, &s) == 0) {
page_tmp = (char *)malloc(s.st_size + 1);
if (page_tmp == NULL) {
page_tmp = strdup("Missing Content");
if (page_tmp == NULL) {
return -1;
}
memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
free(page_tmp);
page_tmp = NULL;
}
}
if (page_tmp == NULL) {
page_tmp = (char *)malloc(16);
if (page_tmp == NULL) {
return -1;
}
sprintf(page_tmp, "Missing Content");
}
page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
free(page_tmp);
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
@ -256,38 +236,19 @@ int www_404(char *header, char *footer, struct MHD_Connection *connection) {
snprintf(buffer, PATH_MAX, "%s/404.tpl", conf.www_path);
page_tmp = NULL;
page_tmp = file2str(buffer);
if (stat(buffer, &s) == 0) {
page_tmp = (char *)malloc(s.st_size + 1);
if (page_tmp == NULL) {
page_tmp = (char *)strdup("Missing Content");
if (page_tmp == NULL) {
return -1;
}
memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
free(page_tmp);
page = NULL;
}
}
if (page_tmp == NULL) {
page_tmp = (char *)malloc(16);
if (page_tmp == NULL) {
return -1;
}
sprintf(page_tmp, "Missing Content");
}
page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
free(page_tmp);
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
@ -310,38 +271,19 @@ int www_403(char *header, char *footer, struct MHD_Connection *connection) {
snprintf(buffer, PATH_MAX, "%s/403.tpl", conf.www_path);
page_tmp = NULL;
page_tmp = file2str(buffer);
if (stat(buffer, &s) == 0) {
page_tmp = (char *)malloc(s.st_size + 1);
if (page_tmp == NULL) {
page_tmp = strdup("Missing Content");
if (page_tmp == NULL) {
return -1;
}
memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
free(page_tmp);
page_tmp = NULL;
}
}
if (page_tmp == NULL) {
page_tmp = (char *)malloc(16);
if (page_tmp == NULL) {
return -1;
}
sprintf(page_tmp, "Missing Content");
}
page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
free(page_tmp);
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
response = MHD_create_response_from_buffer(strlen(whole_page), (void *)whole_page, MHD_RESPMEM_MUST_FREE);
@ -428,7 +370,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
if (strcmp(method, "GET") == 0) {
if (*ptr == NULL) {
con_inf = (struct connection_info_s *)malloc(sizeof(struct connection_info_s));
con_inf = (struct connection_info_s *)malloz(sizeof(struct connection_info_s));
if (!con_inf) {
return MHD_NO;
}
@ -442,7 +384,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
}
} else if (strcmp(method, "POST") == 0) {
if (*ptr == NULL) {
con_inf = (struct connection_info_s *)malloc(sizeof(struct connection_info_s));
con_inf = (struct connection_info_s *)malloz(sizeof(struct connection_info_s));
if (!con_inf) {
return MHD_NO;
}
@ -462,30 +404,13 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
snprintf(buffer, PATH_MAX, "%s/header.tpl", conf.www_path);
header_tmp = NULL;
header_tmp = file2str(buffer);
if (stat(buffer, &s) == 0) {
header_tmp = (char *)malloc(s.st_size + 1);
if (header_tmp == NULL) {
header_tmp = str5dup("<HTML>\n<HEAD>\n<TITLE>", conf.bbs_name, "</TITLE>\n</HEAD>\n<BODY>\n<H1>", conf.bbs_name, "</H1><HR />");
if (header_tmp == NULL) {
return MHD_NO;
}
memset(header_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
fread(header_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
free(header_tmp);
header_tmp = NULL;
}
}
if (header_tmp == NULL) {
header_tmp = (char *)malloc(strlen(conf.bbs_name) * 2 + 61);
if (header_tmp == NULL) {
return MHD_NO;
}
sprintf(header_tmp, "<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n</HEAD>\n<BODY>\n<H1>%s</H1><HR />", conf.bbs_name, conf.bbs_name);
}
header = str_replace(header_tmp, "@@WWW_URL@@", conf.www_url);
@ -493,32 +418,14 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
snprintf(buffer, PATH_MAX, "%s/footer.tpl", conf.www_path);
footer_tmp = NULL;
footer_tmp = file2str(buffer);
if (stat(buffer, &s) == 0) {
footer_tmp = (char *)malloc(s.st_size + 1);
if (footer_tmp == NULL) {
footer_tmp = strdup("<HR />Powered by Magicka BBS</BODY></HTML>");
if (footer_tmp == NULL) {
free(header);
return MHD_NO;
}
memset(footer_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
fread(footer_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
free(footer_tmp);
footer_tmp = NULL;
}
}
if (footer_tmp == NULL) {
footer_tmp = (char *)malloc(43);
if (footer_tmp == NULL) {
free(header);
return MHD_NO;
}
sprintf(footer_tmp, "<HR />Powered by Magicka BBS</BODY></HTML>");
}
footer = str_replace(footer_tmp, "@@WWW_URL@@", conf.www_url);
@ -529,42 +436,21 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
snprintf(buffer, PATH_MAX, "%s/index.tpl", conf.www_path);
page_tmp = NULL;
page_tmp = file2str(buffer);
if (stat(buffer, &s) == 0) {
page_tmp = (char *)malloc(s.st_size + 1);
if (page_tmp == NULL) {
page_tmp = strdup("Missing Content");
if (page_tmp == NULL) {
free(header);
free(footer);
return MHD_NO;
}
memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
free(page_tmp);
page_tmp = NULL;
}
}
if (page_tmp == NULL) {
page_tmp = (char *)malloc(16);
if (page_tmp == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page_tmp, "Missing Content");
}
page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
free(page_tmp);
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strcasecmp(url, "/last10/") == 0 || strcasecmp(url, "/last10") == 0) {
page = www_last10();
if (page == NULL) {
@ -572,9 +458,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strcasecmp(url, "/blog") == 0 || strcasecmp(url, "/blog/") == 0) {
page = www_blog();
if (page == NULL) {
@ -582,9 +466,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -600,9 +482,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strcasecmp(url, "/email/new") == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -618,9 +498,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/email/delete/", 14) == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -632,30 +510,26 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
}
email = strtol(&url[14], &endptr, 10);
if (email == -1 || !www_email_delete(con_inf->user, email)) {
page = (char *)malloc(31);
page = strdup("<h1>Error Deleting Email.</h1>");
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page, "<h1>Error Deleting Email.</h1>");
} else {
page = (char *)malloc(24);
page = strdup("<h1>Email Deleted!</h1>");
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page, "<h1>Email Deleted!</h1>");
}
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/email/", 7) == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -677,9 +551,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strcasecmp(url, "/msgs/") == 0 || strcasecmp(url, "/msgs") == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -695,9 +567,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/msgs/flag/", 11) == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -787,9 +657,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_NO;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/msgs/", 6) == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -851,9 +719,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_YES;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/static/", 8) == 0) {
// sanatize path
if (strstr(url, "/..") != NULL) {
@ -885,8 +751,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
if (stat(buffer, &s) == 0 && S_ISREG(s.st_mode)) {
fno = open(buffer, O_RDONLY);
if (fno != -1) {
//static_buffer = (char *)malloc(s.st_size + 1);
//static_buffer = (char *)malloz(s.st_size + 1);
//read(fno, static_buffer, s.st_size);
response = MHD_create_response_from_fd(s.st_size, fno);
//response = MHD_create_response_from_buffer (s.st_size, (void*) static_buffer, MHD_RESPMEM_MUST_FREE);
@ -918,8 +783,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
}
} else if (strcasecmp(url, "/files/areas/") == 0 || strcasecmp(url, "/files/areas") == 0) {
page = www_files_areas();
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/files/areas/", 13) == 0) {
file_dir = -1;
file_sub = -1;
@ -1021,9 +885,7 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
free(footer);
return MHD_YES;
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strncasecmp(url, "/files/", 7) == 0) {
filename = www_decode_hash(&url[7]);
if (filename != NULL) {
@ -1116,26 +978,21 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
}
}
if (!www_send_email(con_inf->user, to, subj, body)) {
page = (char *)malloc(50);
page = strdup("<h1>Error Sending Email (Check User Exists?)</h1>");
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page, "<h1>Error Sending Email (Check User Exists?)</h1>");
} else {
page = (char *)malloc(21);
page = strdup("<h1>Email Sent!</h1>");
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page, "<h1>Email Sent!</h1>");
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else if (strcasecmp(url, "/msgs/") == 0 || strcasecmp(url, "/msgs") == 0) {
con_inf->user = www_auth_ok(connection, url_);
@ -1185,26 +1042,21 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c
}
if (!www_send_msg(con_inf->user, to, subj, conference, area, replyid, body)) {
page = (char *)malloc(31);
page = strdup("<h1>Error Sending Message</h1>");
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page, "<h1>Error Sending Message</h1>");
} else {
page = (char *)malloc(23);
page = strdup("<h1>Message Sent!</h1>");
if (page == NULL) {
free(header);
free(footer);
return MHD_NO;
}
sprintf(page, "<h1>Message Sent!</h1>");
}
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
whole_page = str3dup(header, page, footer);
} else {
free(header);
free(footer);

View File

@ -22,10 +22,9 @@ char *www_blog() {
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>System Blog</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {

View File

@ -91,8 +91,7 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, conf.default_tagline);
body = (char *)malloc(strlen(ibody) + strlen(buffer) + 1);
memset(body, 0, strlen(ibody) + strlen(buffer) + 1);
body = (char *)malloz(strlen(ibody) + strlen(buffer) + 1);
pos = 0;
for (i = 0; i < strlen(ibody); i++) {
if (ibody[i] != '\n') {
@ -147,10 +146,9 @@ char *www_new_email() {
int len;
char buffer[4096];
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>New Email</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {
@ -240,10 +238,9 @@ char *www_email_display(struct user_record *user, int email) {
char *update_seen_sql = "UPDATE email SET seen=1 WHERE id=?";
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
@ -545,10 +542,9 @@ char *www_email_summary(struct user_record *user) {
"date INTEGER,"
"seen INTEGER);";
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>Your Email</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {

View File

@ -12,7 +12,7 @@ extern struct user_record *gUser;
extern char *aha(char *input);
static char *www_decode(char *clean_url) {
char *url = (char *)malloc(strlen(clean_url) + 1);
char *url = (char *)malloz(strlen(clean_url) + 1);
int i;
int j = 0;
unsigned char c;
@ -37,7 +37,7 @@ static char *www_decode(char *clean_url) {
}
static char *www_encode(char *url) {
char *clean_url = (char *)malloc(strlen(url) * 3 + 1);
char *clean_url = (char *)malloz(strlen(url) * 3 + 1);
int i;
int j;
@ -257,9 +257,7 @@ char *www_create_link(int dir, int sub, int fid) {
sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid);
hashid = (char *)malloc(sizereq + 1);
memset(hashid, 0, sizereq + 1);
hashid = (char *)malloz(sizereq + 1);
if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) {
hashids_free(hashids);
@ -298,10 +296,9 @@ char *www_files_display_listing(int dir, int sub) {
int i;
char *clean_url;
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
snprintf(buffer, 4096, "<div class=\"content-header\"><h2>Files: %s - %s</h2></div>\n", conf.file_directories[dir]->name, conf.file_directories[dir]->file_subs[sub]->name);
if (len + strlen(buffer) > max_len - 1) {
@ -428,10 +425,9 @@ char *www_files_areas() {
int i;
int j;
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>File Directories</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {
@ -486,7 +482,7 @@ char *www_files_get_from_area(int dir, int sub, char *clean_file) {
}
}
filenamelike = (char *)malloc(strlen(file) + 3 + extra);
filenamelike = (char *)malloz(strlen(file) + 3 + extra);
i = 0;
filenamelike[i++] = '%';

View File

@ -31,10 +31,9 @@ char *www_last10() {
i = 0;
}
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>Last 10 Callers</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {

View File

@ -30,8 +30,7 @@ char *www_sanitize(char *inp) {
}
}
result = (char *)malloc(len + 1);
memset(result, 0, len + 1);
result = (char *)malloz(len + 1);
len = 0;
for (i = 0; i < strlen(inp); i++) {
if (inp[i] == '<') {
@ -65,10 +64,9 @@ char *www_msgs_arealist(struct user_record *user) {
char buffer[4096];
int i, j;
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>Message Conferences</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {
@ -129,10 +127,9 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
return NULL;
}
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>%s - %s</h2></div>\n", conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name);
if (len + strlen(buffer) > max_len - 1) {
@ -326,39 +323,19 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
subject = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(subject, 0, jsp->Fields[z]->DatLen + 1);
memcpy(subject, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) {
from = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(from, 0, jsp->Fields[z]->DatLen + 1);
memcpy(from, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) {
to = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(to, 0, jsp->Fields[z]->DatLen + 1);
memcpy(to, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) {
daddress = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(daddress, 0, jsp->Fields[z]->DatLen + 1);
memcpy(daddress, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) {
oaddress = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(oaddress, 0, jsp->Fields[z]->DatLen + 1);
memcpy(oaddress, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
msgid = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(msgid, 0, jsp->Fields[z]->DatLen + 1);
memcpy(msgid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) {
replyid = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(replyid, 0, jsp->Fields[z]->DatLen + 1);
memcpy(replyid, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) {
from = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) {
to = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) {
daddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) {
oaddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) {
replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
}
JAM_DelSubPacket(jsp);
@ -407,8 +384,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
return NULL;
}
}
body = (char *)malloc(jmh.TxtLen + 1);
memset(body, 0, jmh.TxtLen + 1);
body = (char *)malloz(jmh.TxtLen + 1);
JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body);
@ -427,10 +403,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
JAM_CloseMB(jb);
free(jb);
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><a href=\"%smsgs/%d/%d\"><h2>%s - %s</h2></a></div>\n", conf.www_url, conference, area, conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name);
if (len + strlen(buffer) > max_len - 1) {
@ -542,7 +517,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
strcat(page, buffer);
len += strlen(buffer);
aha_text = (char *)malloc(jmh.TxtLen + 1);
aha_text = (char *)malloz(jmh.TxtLen + 1);
memcpy(aha_text, body, jmh.TxtLen);
aha_text[jmh.TxtLen] = '\0';
@ -647,7 +622,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
strcat(page, buffer);
len += strlen(buffer);
replybody = (char *)malloc(strlen(body) + 1);
replybody = (char *)malloz(strlen(body) + 1);
l2 = 0;
for (l1 = 0; l1 < strlen(body); l1++) {
@ -813,10 +788,7 @@ static char *www_wordwrap(char *content, int cutoff) {
at = 0;
len = strlen(content);
ret = (char *)malloc(len + 1);
if (ret == NULL) {
return NULL;
}
ret = (char *)malloz(len + 1);
line_count = 0;
quote_line = 0;
@ -889,7 +861,6 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
char *body2;
char *tagline;
struct utsname name;
int pos;
char *body3;
iconv_t ic;
@ -1060,7 +1031,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
free(jb);
return 0;
}
body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer));
body3 = str2dup(body2, buffer);
if (body3 == NULL) {
free(body2);
JAM_UnlockMB(jb);
@ -1070,12 +1041,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
return 0;
}
memset(body3, 0, strlen(body2) + 2 + strlen(buffer));
pos = 0;
sprintf(body3, "%s%s", body2, buffer);
free(body2);
body2 = (char *)malloc(strlen(body3) + 1);
body2 = (char *)malloz(strlen(body3) + 1);
ic = iconv_open("CP437", "UTF-8");
@ -1123,10 +1090,9 @@ char *www_new_msg(struct user_record *user, int conference, int area) {
int len;
char buffer[4096];
page = (char *)malloc(4096);
page = (char *)malloz(4096);
max_len = 4096;
len = 0;
memset(page, 0, 4096);
sprintf(buffer, "<div class=\"content-header\"><h2>New Message</h2></div>\n");
if (len + strlen(buffer) > max_len - 1) {