forked from teddy-zhng/buffer-overflow-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhigh_score.c
58 lines (49 loc) · 1.89 KB
/
high_score.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include "high_score.h"
#include "helper.h"
#define MAX_BUF_SIZE (0x100)
char winners_list[MAX_BUF_SIZE] = {0};
char outro_message[MAX_BUF_SIZE] = {0};
bool handle_reset_winner_data(int client_fd, char* client_str)
{
memset(winners_list, 0, sizeof(winners_list));
memset(outro_message, 0, sizeof(outro_message));
strcpy(outro_message, "\nBetter Luck to our other participants next time!\n" );
char *success_str = "reset winner success\n";
printf("%s", success_str);
respond_str_to_client(client_fd, success_str);
return true;
}
bool handle_add_winner(int client_fd, char* client_str) {
char winner_name[0x80];
if (!get_buffer_from_client(client_fd, winner_name, sizeof(winner_name))) {
printf("handle_add_winner error: get_buffer_from_client failed\n");
return false;
}
strncpy(winners_list, winner_name, sizeof(winners_list));
char *success_str = "handle_add_winner success!\n";
printf("%s", success_str);
respond_str_to_client(client_fd, success_str);
return true;
}
bool handle_set_outro_message(int client_fd, char* client_str) {
if (!get_buffer_from_client(client_fd, outro_message, sizeof(outro_message))) {
printf("handle_set_outro_message error: get_buffer_from_client failed\n");
return false;
}
char *success_str = "handle_set_outro_message success!\n";
printf("%s", success_str);
respond_str_to_client(client_fd, success_str);
return true;
}
bool handle_report_winners(int client_fd, char* client_str) {
char msg_to_user[MAX_BUF_SIZE];
int bytes_written = snprintf(msg_to_user, sizeof(msg_to_user), "**WINNER LIST**\n%s\n*** :) ***", winners_list);
snprintf(msg_to_user + bytes_written, sizeof(msg_to_user) - bytes_written, "%s", outro_message);
respond_str_to_client(client_fd, msg_to_user);
return true;
}