From f537dafa775307255019df9a119c8f81a52607ca Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Tue, 6 Oct 2020 14:19:06 +0200 Subject: #941 Use fixed length strings in og_computer and og_dbi_get_computer_info This patch is a refactor for og_computer and og_dbi_get_computer_info. It now uses fixed lenght strings to make it more reliable and avoid errors if the DB is not returning a null ended string. --- src/dbi.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/dbi.h') diff --git a/src/dbi.h b/src/dbi.h index 84b898c..e92ce43 100644 --- a/src/dbi.h +++ b/src/dbi.h @@ -23,10 +23,16 @@ void og_dbi_close(struct og_dbi *db); #define OG_DB_COMPUTER_NAME_MAXLEN 100 #define OG_DB_CENTER_NAME_MAXLEN 100 #define OG_DB_ROOM_NAME_MAXLEN 100 +#define OG_DB_SERIAL_NUMBER_MAXLEN 25 #define OG_DB_IMAGE_NAME_MAXLEN 50 #define OG_DB_FILESYSTEM_MAXLEN 16 +#define OG_DB_NETDRIVER_MAXLEN 30 +#define OG_DB_NETIFACE_MAXLEN 4 +#define OG_DB_LIVEDIR_MAXLEN 50 #define OG_DB_INT8_MAXLEN 8 +#define OG_DB_BOOT_MAXLEN 30 #define OG_DB_INT_MAXLEN 11 +#define OG_DB_MAC_MAXLEN 15 #define OG_DB_IP_MAXLEN 15 #define OG_DB_SMALLINT_MAXLEN 6 @@ -59,20 +65,19 @@ struct og_computer { unsigned int id; bool maintenance; bool remote; - char *serial_number; - char *netdriver; - char *netiface; - char *netmask; - char *livedir; - char *name; - char *boot; - char *mac; - char *ip; + char serial_number[OG_DB_SERIAL_NUMBER_MAXLEN + 1]; + char netdriver[OG_DB_NETDRIVER_MAXLEN + 1]; + char name[OG_DB_COMPUTER_NAME_MAXLEN + 1]; + char netiface[OG_DB_NETIFACE_MAXLEN + 1]; + char livedir[OG_DB_LIVEDIR_MAXLEN + 1]; + char netmask[OG_DB_IP_MAXLEN + 1]; + char boot[OG_DB_BOOT_MAXLEN + 1]; + char mac[OG_DB_MAC_MAXLEN + 1]; + char ip[OG_DB_IP_MAXLEN + 1]; }; struct in_addr; int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, struct in_addr addr); -void og_dbi_free_computer_info(struct og_computer *computer); #endif -- cgit v1.2.3-18-g5258