[plane] fix *** stack smashing detected *** (because time_t for random) + removed serializer

This commit is contained in:
xdrm-brackets 2017-04-08 18:37:14 +02:00
parent d2afb8f65e
commit 61581e393d
5 changed files with 21 additions and 153 deletions

View File

@ -9,12 +9,9 @@ default: all
lib/network/tcp/client.o: lib/header.h lib/network/tcp/client.h lib/network/tcp/client.c
gcc $(CFLAGS) -c -o lib/network/tcp/client.o lib/network/tcp/client.c
lib/network/format/serializer.o: lib/network/format/serializer.h lib/network/format/serializer.c
gcc $(CFLAGS) -c -o lib/network/format/serializer.o lib/network/format/serializer.c
# Compiles the Plane
boot: lib/network/tcp/client.o lib/network/format/serializer.o plane.h plane.c
gcc $(CFLAGS) -o boot lib/network/tcp/client.o lib/network/format/serializer.o plane.c -lm
boot: lib/network/tcp/client.o plane.h plane.c
gcc $(CFLAGS) -o boot lib/network/tcp/client.o plane.c -lm
# Run full compilation

View File

@ -22,8 +22,8 @@
#include <arpa/inet.h>
/* vars */
#define SRV_HOST "localhost"
#define SRV_PORT 4444
#define SRV_HOST "127.0.0.1"
#define SRV_PORT 0x504c
#define MAX_BUF_LEN 512

View File

@ -1,64 +0,0 @@
#include "serializer.h"
int parse_plane_request(const char* pIn, struct plane_request* pOut){
/* 1. Check buffer length */
if( strlen(pIn)*sizeof(char) != sizeof(struct plane_request) )
return -1;
/* 2. Parse buffer */
memcpy(pOut, pIn, (size_t) sizeof(struct plane_request));
return 0;
}
int parse_viewterm_request(const char* pIn, struct vterm_request* pOut){
/* 1. Check buffer length */
if( strlen(pIn)*sizeof(char) != sizeof(struct vterm_request) )
return -1;
/* 2. Parse buffer */
memcpy(pOut, pIn, sizeof(struct vterm_request));
return 0;
}
int parse_ctrlterm_request(const char* pIn, struct cterm_request* pOut){
/* 1. Check buffer length */
if( strlen(pIn)*sizeof(char) != sizeof(struct cterm_request) )
return -1;
/* 2. Parse buffer */
memcpy(pOut, pIn, sizeof(struct cterm_request));
return 0;
}
int serialize_term_response(const struct term_response* pIn, char* pOut, const size_t pSize){
/* 1. Check buffer length */
if( sizeof(struct term_response) > pSize*sizeof(char) )
return -1;
/* 2. Serialize response into buffer */
memcpy(pOut, pIn, sizeof(struct term_response));
return 0;
}

View File

@ -1,65 +0,0 @@
#ifndef _LIB_NETWORK_FORMAT_SERIALIZER_H_
#define _LIB_NETWORK_FORMAT_SERIALIZER_H_
#include <string.h>
#include "../../../plane.h"
struct plane_request{ // Plane Request
struct coord co;
struct control ct;
};
struct vterm_request{ // ViewTerminal Request
char flags;
};
struct term_response{ // Terminal-s Response
char flags;
struct coord co;
struct control ct;
};
struct cterm_request{ // ControlTerminal Request
char flags;
int z;
struct control ct;
};
/* Parse a plane request ('char*' to 'struct plane_request')
*
* @history
* [1] Check if buffer have correct size (according to destination struct)
* [2] Parse buffer to struct
*
*/
int parse_plane_request(const char* pIn, struct plane_request* pOut);
/* Parse a viewTerminal request ('char*' to 'struct vt_request')
*
* @history
* [1] Check if buffer have correct size (according to destination struct)
* [2] Parse buffer to struct
*
*/
int parse_viewterm_request(const char* pIn, struct vterm_request* pOut);
/* Parse a ctrlTerminal request ('char*' to 'struct ct_request')
*
* @history
* [1] Check if buffer have correct size (according to destination struct)
* [2] Parse buffer to struct
*
*/
int parse_ctrlterm_request(const char* pIn, struct cterm_request* pOut);
/* Serialize a Terminal response ('struct t_response' to 'char*')
*
* @history
* [1] Check if buffer have correct size (according to input struct)
* [2] Serialize struct into buffer
*
*/
int serialize_term_response(const struct term_response* pIn, char* pOut, const size_t pSize);
#endif

View File

@ -68,8 +68,8 @@ void envoyer_caracteristiques(){
// initialise aléatoirement les paramètres initiaux de l'plane
void init_plane(){
// initialisation aléatoire du compteur aléatoire
unsigned int seed;
time( (time_t*) &seed);
time_t seed;
time( &seed);
srandom(seed);
// intialisation des paramètres de l'plane