Fixes on the array size computation.

This work is based on feedback from Thomas Schlichter.
His comments and suggestions were made just after the original MR was merged.

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
This commit is contained in:
Raphael Defosseux
2021-06-14 14:56:01 +02:00
parent 530b74dde9
commit 2a6ebaaaae
+9 -9
View File
@@ -96,14 +96,14 @@ static void read_pipe(int p, char *b, int size) {
} }
} }
static int baseRunTimeCommand(char* cmd) { static int baseRunTimeCommand(char* cmd, size_t cmdSize) {
FILE *fp; FILE *fp;
size_t retSize = 0; size_t retSize = 0;
fp = popen(cmd, "r"); fp = popen(cmd, "r");
memset(cmd, 1, sizeof(*cmd)); memset(cmd, 0, cmdSize);
retSize = fread(cmd, 1, sizeof(*cmd), fp); retSize = fread(cmd, 1, cmdSize, fp);
fclose(fp); fclose(fp);
if (retSize == 0) { if (retSize == 0) {
@@ -115,26 +115,26 @@ static int baseRunTimeCommand(char* cmd) {
int checkIfFedoraDistribution(void) { int checkIfFedoraDistribution(void) {
char cmd[200]; char cmd[200];
memset(cmd, 1, 200); memset(cmd, 0, 200);
sprintf(cmd, "cat /etc/os-release | grep ID_LIKE | grep -ic fedora || true"); sprintf(cmd, "cat /etc/os-release | grep ID_LIKE | grep -ic fedora || true");
return baseRunTimeCommand(cmd); return baseRunTimeCommand(cmd, 200);
} }
int checkIfGenericKernelOnFedora(void) { int checkIfGenericKernelOnFedora(void) {
char cmd[200]; char cmd[200];
memset(cmd, 1, 200); memset(cmd, 0, 200);
sprintf(cmd, "uname -a | grep -c rt || true"); sprintf(cmd, "uname -a | grep -c rt || true");
return (1 - baseRunTimeCommand(cmd)); return (1 - baseRunTimeCommand(cmd, 200));
} }
int checkIfInsideContainer(void) { int checkIfInsideContainer(void) {
char cmd[200]; char cmd[200];
int res = 0; int res = 0;
memset(cmd, 1, 200); memset(cmd, 0, 200);
sprintf(cmd, "cat /proc/self/cgroup | egrep -c 'libpod|podman|kubepods' || true"); sprintf(cmd, "cat /proc/self/cgroup | egrep -c 'libpod|podman|kubepods' || true");
res = baseRunTimeCommand(cmd); res = baseRunTimeCommand(cmd, 200);
if (res > 0) if (res > 0)
return 1; return 1;
else else