summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-06 14:19:06 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-10-06 16:04:17 +0200
commitf537dafa775307255019df9a119c8f81a52607ca (patch)
tree3b3863f88e514ddbfc5d25be335cdb478a5a0174 /src/dbi.c
parent27fbc658293db97775385f6cc54a36bf0d6c454d (diff)
#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.
Diffstat (limited to 'src/dbi.c')
-rw-r--r--src/dbi.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 7d7ba64..3c4ae51 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -13,6 +13,7 @@
#include "dbi.h"
#include <syslog.h>
#include <string.h>
+#include <stdio.h>
struct og_dbi *og_dbi_open(struct og_dbi_config *config)
{
@@ -93,19 +94,28 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
}
computer->id = dbi_result_get_uint(result, "idordenador");
- computer->name = strdup(dbi_result_get_string(result, "nombreordenador"));
- computer->serial_number = strdup(dbi_result_get_string(result, "numserie"));
- computer->ip = strdup(dbi_result_get_string(result, "ip"));
- computer->mac = strdup(dbi_result_get_string(result, "mac"));
+ snprintf(computer->name, sizeof(computer->name), "%s",
+ dbi_result_get_string(result, "nombreordenador"));
+ snprintf(computer->serial_number, sizeof(computer->serial_number), "%s",
+ dbi_result_get_string(result, "numserie"));
+ snprintf(computer->ip, sizeof(computer->ip), "%s",
+ dbi_result_get_string(result, "ip"));
+ snprintf(computer->mac, sizeof(computer->mac), "%s",
+ dbi_result_get_string(result, "mac"));
computer->room = dbi_result_get_uint(result, "idaula");
computer->hardware_id = dbi_result_get_uint(result, "idperfilhard");
computer->repo_id = dbi_result_get_uint(result, "idrepositorio");
- computer->netmask = strdup(dbi_result_get_string(result, "mascara"));
- computer->boot = strdup(dbi_result_get_string(result, "arranque"));
- computer->netiface = strdup(dbi_result_get_string(result, "netiface"));
- computer->netdriver = strdup(dbi_result_get_string(result, "netdriver"));
+ snprintf(computer->netmask, sizeof(computer->netmask), "%s",
+ dbi_result_get_string(result, "mascara"));
+ snprintf(computer->boot, sizeof(computer->boot), "%s",
+ dbi_result_get_string(result, "arranque"));
+ snprintf(computer->netiface, sizeof(computer->netiface), "%s",
+ dbi_result_get_string(result, "netiface"));
+ snprintf(computer->netdriver, sizeof(computer->netdriver), "%s",
+ dbi_result_get_string(result, "netdriver"));
computer->procedure_id = dbi_result_get_uint(result, "idproautoexec");
- computer->livedir = strdup(dbi_result_get_string(result, "oglivedir"));
+ snprintf(computer->livedir, sizeof(computer->livedir), "%s",
+ dbi_result_get_string(result, "oglivedir"));
computer->remote = dbi_result_get_uint(result, "inremotepc") != 0;
computer->maintenance = dbi_result_get_uint(result, "maintenance") != 0;
@@ -113,16 +123,3 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
return 0;
}
-
-void og_dbi_free_computer_info(struct og_computer *computer)
-{
- free(computer->serial_number);
- free(computer->netdriver);
- free(computer->netiface);
- free(computer->netmask);
- free(computer->livedir);
- free(computer->name);
- free(computer->boot);
- free(computer->mac);
- free(computer->ip);
-}