/** * Give a food item to a customer * * @param c Customer * @param ftype Type of food * @param food Food item * @return SUCCESS on success, else -1 if invalid ftype */ static char cgc_give_food_to_customer(Customer *c, FoodTypes ftype, void *food) { char ret = SUCCESS; unsigned int bufsz = 0; void *buf = NULL; // get size of food using provided ftype switch (ftype) { case APP_TYPE: DBG("food size as appetizer\n"); bufsz = sizeof(Appetizer); break; case MEAL_TYPE: DBG("food size as Meal\n"); bufsz = sizeof(Meal); break; case DES_TYPE: DBG("food size as Dessert\n"); bufsz = sizeof(Dessert); break; default: DBG("invalid ftype\n"); ret = -1; } #ifndef PATCHED_9 // VULN: table.status can be mismatched with ftype provided by user. // Use table.status to get location to cgc_write food into Customer and the proper food inspection function ftype = cgc_get_delivery_foodtype_from_tablestatus(table.status); #endif switch (ftype) { case APP_TYPE: DBG("buf as appetizer\n"); buf = &c->a; c->fi = cgc_inspect_appetizer; break; case MEAL_TYPE: DBG("buf as Meal\n"); buf = &c->m; c->fi = cgc_inspect_meal; break; case DES_TYPE: DBG("buf as Dessert\n"); buf = &c->d; c->fi = cgc_inspect_dessert; break; default: DBG("invalid ftype\n"); ret = -1; } if (SUCCESS == ret) { cgc_accept_food(food, buf, bufsz); ret = c->fi(buf, c->id); } #ifdef DEBUG switch (ftype) { case APP_TYPE: DBG("wrote appetizer\n"); print_appetizer(&c->a); break; case MEAL_TYPE: DBG("wrote meal\n"); print_meal(&c->m); break; case DES_TYPE: DBG("wrote dessert\n"); print_dessert(&c->d); break; default: DBG("invalid ftype\n"); ret = -1; } print_customer(c); #endif return ret; }
void print_customer(Customer *c) { DBG("Customer id: %U, next: %H\n", c->id, c->next); print_appetizer(&c->a); print_meal(&c->m); print_dessert(&c->d); }