Skip to content

Commit

Permalink
strncpy is not safe + memory optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Nov 4, 2021
1 parent 2146014 commit 974ff5f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/platform_console/cmd_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions components/platform_console/cmd_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) );
Expand Down
6 changes: 3 additions & 3 deletions components/services/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ 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;
int A, B, SW;
rotary_handler handler;
} rotary;

static struct {
static EXT_RAM_ATTR struct {
RingbufHandle_t rb;
infrared_handler handler;
} infrared;
Expand Down
4 changes: 2 additions & 2 deletions components/services/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions components/squeezelite/displayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions components/wifi-manager/wifi_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 974ff5f

Please sign in to comment.