From ed9fd0390a5caaf925823164230ccfdf8cb476e9 Mon Sep 17 00:00:00 2001 From: Per Cederqvist Date: Sat, 17 Oct 1998 16:48:24 +0000 Subject: [PATCH] (copy_conference): Fixed a memory corruption problem that was introduced when Local_to_global was introduced. (copy_person): Likewise. (copy_text_stat): Added a const qualifier. Rewritten to decrease the probability that the same kind of bug is introduced here, that is, assign each field separately instead of assigning the entire struct at once. (copy_aux_item_list): Now static. Rewritten as above. (coy_aux_item): Added const qualifier. Rewritten as above. --- src/server/memory.c | 68 +++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/src/server/memory.c b/src/server/memory.c index 66ff7f57..77267ee4 100644 --- a/src/server/memory.c +++ b/src/server/memory.c @@ -1,5 +1,5 @@ /* - * $Id: memory.c,v 0.24 1998/07/26 16:45:28 ceder Exp $ + * $Id: memory.c,v 0.25 1998/10/17 16:48:24 ceder Exp $ * Copyright (C) 1991, 1992, 1993, 1994, 1996 Lysator Academic Computer Association. * * This file is part of the LysKOM server. @@ -29,7 +29,7 @@ */ static const char * -rcsid = "$Id: memory.c,v 0.24 1998/07/26 16:45:28 ceder Exp $"; +rcsid = "$Id: memory.c,v 0.25 1998/10/17 16:48:24 ceder Exp $"; #include "rcs.h" USE(rcsid); @@ -65,6 +65,8 @@ static void clear_membership (Membership *mship); static Membership copy_membership (Membership m); static void clear_membership_list (Membership_list *mlist); static Membership_list copy_membership_list (Membership_list ml); +static void copy_aux_item_list(Aux_item_list *dest, + const Aux_item_list *src); /* Conf_type */ @@ -118,13 +120,23 @@ copy_conference (const Conference *o) Conference *c; c = alloc_conference(); - *c = *o; - c->name = EMPTY_STRING; + c->type = o->type; + c->creator = o->creator; + c->supervisor = o->supervisor; + c->permitted_submitters = o->permitted_submitters; + c->super_conf = o->super_conf; + c->creation_time = o->creation_time; + c->presentation = o->presentation; + c->last_written = o->last_written; + c->msg_of_day = o->msg_of_day; + c->nice = o->nice; + c->expire = o->expire; s_strcpy(&c->name, o->name); - c->members = copy_member_list(o->members); - l2g_copy(&c->texts, &o->texts); + c->highest_aux = o->highest_aux; copy_aux_item_list(&c->aux_item_list, &o->aux_item_list); + c->members = copy_member_list(o->members); + l2g_copy(&c->texts, &o->texts); return c; } @@ -370,18 +382,28 @@ clear_person(Person *person) } Person * -copy_person(Person *p) +copy_person(const Person *p) { Person *c; c = alloc_person(); - *c = *p; - c->username = EMPTY_STRING; + c->user_area = p->user_area; + c->privileges = p->privileges; + c->flags = p->flags; + c->last_login = p->last_login; + c->total_time_present = p->total_time_present; + c->sessions = p->sessions; + c->created_lines = p->created_lines; + c->created_bytes = p->created_bytes; + c->read_texts = p->read_texts; + c->no_of_text_fetches = p->no_of_text_fetches; + c->created_persons = p->created_persons; + c->created_confs = p->created_confs; s_strcpy(&c->username, p->username); - l2g_copy(&c->created_texts, &p->created_texts); c->marks = copy_mark_list(p->marks); c->conferences = copy_membership_list(p->conferences); + memcpy(&c->pwd, &p->pwd, sizeof(Password)); return c; } @@ -537,12 +559,19 @@ clear_text_stat(Text_stat *t) } Text_stat * -copy_text_stat(Text_stat *t) +copy_text_stat(const Text_stat *t) { Text_stat *c; c = alloc_text_stat(); - *c = *t; + c->creation_time = t->creation_time; + c->file_pos = t->file_pos; + c->author = t->author; + c->no_of_lines = t->no_of_lines; + c->no_of_chars = t->no_of_chars; + c->no_of_marks = t->no_of_marks; + c->no_of_misc = t->no_of_misc; + c->highest_aux = t->highest_aux; c->misc_items = smalloc(c->no_of_misc * sizeof(Misc_info)); memcpy(c->misc_items, t->misc_items, c->no_of_misc * sizeof(Misc_info)); copy_aux_item_list(&c->aux_item_list, @@ -634,13 +663,13 @@ free_aux_item_list(Aux_item_list *list) list->items = NULL; } -void +static void copy_aux_item_list(Aux_item_list *dest, const Aux_item_list *src) { unsigned long i; - *dest = *src; + dest->length = src->length; dest->items = smalloc(sizeof(Aux_item) * src->length); for (i = 0; i < src->length; i++) { @@ -656,9 +685,14 @@ init_aux_item_list(Aux_item_list *list) } void -copy_aux_item(Aux_item *dest, Aux_item *src) -{ - *dest = *src; +copy_aux_item(Aux_item *dest, const Aux_item *src) +{ + dest->aux_no = src->aux_no; + dest->creator = src->creator; + dest->sent_at = src->sent_at; + dest->flags = src->flags; + dest->inherit_limit = src->inherit_limit; + dest->tag = src->tag; dest->data = EMPTY_STRING; s_strcpy(&dest->data, src->data); } -- GitLab