Răsfoiți Sursa

strncpy is not safe + memory optimization

Philippe G 3 ani în urmă
părinte
comite
974ff5fa68

+ 1 - 0
components/platform_console/cmd_config.c

@@ -611,6 +611,7 @@ static int do_i2s_cmd(int argc, char **argv)
 	}
 	if(i2s_args.model_name->count>0 && strlen(i2s_args.model_name->sval[0])>0){
 		strncpy(i2s_dac_pin.model,i2s_args.model_name->sval[0],sizeof(i2s_dac_pin.model));
+		i2s_dac_pin.model[sizeof(i2s_dac_pin.model) - 1] = '\0';
 	}
 	if(!nerrors ){
 		fprintf(f,"Storing i2s parameters.\n");

+ 2 - 0
components/platform_console/cmd_wifi.c

@@ -117,8 +117,10 @@ static bool wifi_join(const char *ssid, const char *pass, int timeout_ms)
     initialise_wifi();
     wifi_config_t wifi_config = { 0 };
     strncpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
+	wifi_config.sta.ssid[sizeof(wifi_config.sta.ssid) - 1] = '\0';
     if (pass) {
         strncpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
+		wifi_config.sta.password[sizeof(wifi_config.sta.password) - 1] = '\0';		
     }
 
     ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );

+ 3 - 3
components/services/buttons.c

@@ -47,14 +47,14 @@ static EXT_RAM_ATTR struct button_s {
 	TimerHandle_t timer;
 } buttons[MAX_BUTTONS];
 
-static struct {
+static EXT_RAM_ATTR struct {
 	int gpio, level;
 	struct button_s *button;
 } polled_gpio[] = { {36, -1, NULL}, {39, -1, NULL}, {-1, -1, NULL} };
 
 static TimerHandle_t polled_timer;
 
-static struct {
+static EXT_RAM_ATTR struct {
 	QueueHandle_t queue;
 	void *client;
 	rotary_encoder_info_t info;
@@ -62,7 +62,7 @@ static struct {
 	rotary_handler handler;
 } rotary;
 
-static struct {
+static EXT_RAM_ATTR struct {
 	RingbufHandle_t rb;
 	infrared_handler handler;
 } infrared;

+ 2 - 2
components/services/led.c

@@ -28,7 +28,7 @@
 
 static const char *TAG = "led";
 
-static struct led_s {
+static EXT_RAM_ATTR struct led_s {
 	gpio_num_t gpio;
 	bool on;
 	int onstate;
@@ -40,7 +40,7 @@ static struct led_s {
 	TimerHandle_t timer;
 } leds[MAX_LED];
 
-static struct {
+static EXT_RAM_ATTR struct {
 	int gpio;
 	int active;
 	int pwm;

+ 3 - 3
components/squeezelite/displayer.c

@@ -244,8 +244,7 @@ static void visu_handler(u8_t *data, int len);
 static void dmxt_handler(u8_t *data, int len);
 static void displayer_task(void* arg);
 
-// PLACEHOLDER
-void *led_display = 0x1000;
+void *led_display;
 
 /* scrolling undocumented information
 	grfs	
@@ -537,7 +536,8 @@ static void show_display_buffer(char *ddram) {
 	char *line2;
 
 	memset(line1, 0, LINELEN+1);
-	strncpy(line1, ddram, LINELEN);
+	strncpy(line1, ddram, LINELEN+1);
+	line1[LINELEN] = '\0';
 	line2 = &(ddram[LINELEN]);
 	line2[LINELEN] = '\0';
 

+ 1 - 0
components/wifi-manager/wifi_manager.c

@@ -292,6 +292,7 @@ void wifi_manager_init_wifi(){
 
 void set_lms_server_details(in_addr_t ip, u16_t hport, u16_t cport){
 	strncpy(lms_server_ip,inet_ntoa(ip),sizeof(lms_server_ip));
+	lms_server_ip[sizeof(lms_server_ip)-1]='\0';
 	ESP_LOGI(TAG,"LMS IP: %s, hport: %d, cport: %d",lms_server_ip, hport, cport);
 	lms_server_port = hport;
 	lms_server_cport = cport;