]> git.alsa-project.org Git - alsa-tools.git/commitdiff
envy24control: fix cast warnings and string array overflows
authorJaroslav Kysela <perex@perex.cz>
Sun, 26 Jan 2025 11:40:23 +0000 (12:40 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 26 Jan 2025 12:08:20 +0000 (13:08 +0100)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
envy24control/config.c
envy24control/envy24control.c
envy24control/levelmeters.c
envy24control/new_process.c
envy24control/profiles.c
envy24control/profiles.h
envy24control/strstr_icase_blank.c

index 6933eef98abe5273f7bd251a7aede5efaa3a59df..c27cf27f10487289bebaad64e23575778ccf37b9 100644 (file)
@@ -46,7 +46,7 @@ void config_close()
 
 void config_set_stereo(GtkWidget *but, gpointer data)
 {
-  gint i=(gint)data;
+  gint i=GPOINTER_TO_INT(data);
   config_stereo[i]=GTK_TOGGLE_BUTTON(but)->active;
 }
 
index 107a843d030e8c0816647eb7f4c5662feb482743..bce41ebbb62acead1464bd26b33c028fc47542e3 100644 (file)
@@ -249,7 +249,7 @@ static void create_mixer_frame(GtkWidget *box, int stream)
        gtk_box_pack_end(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
        /* gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), TRUE); */
        gtk_signal_connect(GTK_OBJECT(toggle), "toggled",
-                          GTK_SIGNAL_FUNC(config_set_stereo), (gpointer)stream-1);
+                          GTK_SIGNAL_FUNC(config_set_stereo), GINT_TO_POINTER(stream-1));
 
        hbox = gtk_hbox_new(TRUE, 6);
        gtk_widget_show(hbox);
@@ -2176,7 +2176,7 @@ int main(int argc, char **argv)
 
        if (! name) {
                /* probe cards */
-               static char cardname[8];
+               static char cardname[16];
                /* FIXME: hardcoded max number of cards */
                for (card_number = 0; card_number < 8; card_number++) {
                        sprintf(cardname, "hw:%d", card_number);
index 24e00dbab37f1bb935e976bc9e12678273124efa..59337213d40ffdbe226569c7dfac9698bbc30c46 100644 (file)
@@ -65,7 +65,7 @@ static GdkGC *get_pen(int idx, int nRed, int nGreen, int nBlue)
        return gc;
 }
 
-static int get_index(gchar *name)
+static int get_index(const gchar *name)
 {
        int result;
 
index 7ea89a672a636ad14749a8480eb8dd317bdd7e62..21684891e882794bfc2541199a64f6d7077d2144 100644 (file)
@@ -20,9 +20,9 @@ int new_process(char * const cmd_line[MAX_PARAM])
        struct stat file_status;
 
        /* memory for storage of function pointers from the signal handling routines */
-       void (*int_stat)();
-       void (*quit_stat)();
-       void (*usr2_stat)();
+       void (*int_stat)(int);
+       void (*quit_stat)(int);
+       void (*usr2_stat)(int);
 
        /*
         * check command file
index 8e23bfda345c79482e74733dbb3d081804839e72..17a418cc8a0069fdf28fe79c39488789bd916f51 100644 (file)
@@ -54,9 +54,9 @@ void subst_tilde_in_filename(char * const filename)
 
        if ((pos_after_tilde = strchr(filename, '~')) != NULL) {
                pos_after_tilde++;
-               strncpy(new_filename, getenv("HOME"), MAX_FILE_NAME_LENGTH);
-               strncpy(new_filename + strlen(new_filename), pos_after_tilde, MAX_FILE_NAME_LENGTH - strlen(new_filename));
-               new_filename[MAX_FILE_NAME_LENGTH - 1] = '\0';
+               strncpy(new_filename, getenv("HOME"), sizeof(new_filename) - 1);
+               strncpy(new_filename + strlen(new_filename), pos_after_tilde, sizeof(new_filename) - strlen(new_filename) - 1);
+               new_filename[sizeof(new_filename) - 1] = '\0';
                strncpy(filename, new_filename, MAX_FILE_NAME_LENGTH);
        }
 }
@@ -522,7 +522,7 @@ int reorganize_profiles(char * const buffer, const int max_length)
 {
        int profile_number, card_number, card_number_max;
        int res;
-       int pos_profile_begin, pos_profile_end, pos_card_begin, pos_card_end, pos_name_header;
+       int pos_profile_begin, pos_card_begin, pos_card_end, pos_name_header;
        int pos_alsa_section_begin, pos_after_alsa_section;
        char header[MAX_SEARCH_FIELD_LENGTH];
        void *buffer_copy = NULL;
@@ -547,7 +547,6 @@ int reorganize_profiles(char * const buffer, const int max_length)
                compose_search_string(header, PROFILE_HEADER_TEMPL, profile_or_card_number_as_str, place_holder, MAX_SEARCH_FIELD_LENGTH);
                header[MAX_SEARCH_FIELD_LENGTH - 1] = '\0';
                snprintf(buffer_copy + strlen(buffer_copy), max_length - strlen(buffer_copy), "%s\n", header);
-               pos_profile_end = get_profile_end(buffer, profile_number);
                /* search max card number in profile */
                card_number_max = get_max_card_number_in_profile(buffer, profile_number);
                for (card_number = 0; card_number <= card_number_max; card_number++)
@@ -641,9 +640,9 @@ int save_restore_alsactl_settings(char * const tmpfile, const int card_number, c
 
 void compose_tmpfile_name(char * const tmpfile, const char * const cfgfile)
 {
-       strncpy(tmpfile, cfgfile, MAX_FILE_NAME_LENGTH);
+       strncpy(tmpfile, cfgfile, MAX_FILE_NAME_LENGTH - 1);
        tmpfile[MAX_FILE_NAME_LENGTH - 1] = '\0';
-       strncpy(tmpfile + strlen(tmpfile), "_alsactl_tmp", MAX_FILE_NAME_LENGTH - strlen(tmpfile));
+       strncpy(tmpfile + strlen(tmpfile), "_alsactl_tmp", MAX_FILE_NAME_LENGTH - strlen(tmpfile) - 1);
        tmpfile[MAX_FILE_NAME_LENGTH - 1] = '\0';
 }
 
index 2063bff0ca35b05655bf18f8cac755e0e7a129ac..b58629111ca6fcf15090603ea8fafd0059c36f7b 100644 (file)
@@ -44,7 +44,7 @@
 #define MAX_PROFILE_SIZE 32768
 #define MAX_SEARCH_FIELD_LENGTH 1024
 #define MAX_FILE_NAME_LENGTH 1024
-#define MAX_NUM_STR_LENGTH 10
+#define MAX_NUM_STR_LENGTH 11
 #define TOKEN_SEP "|"
 #define SEP_CHAR ' '
 
index 8078d2a9ae5624479ed38a43b7254084b4e2615d..6b7c50018d971b6f59fa85ca56337a45b5d26873 100644 (file)
@@ -48,6 +48,7 @@ int strstr_icase_blank(const char * const string1, const char * const string2)
        char search_string[MAX_SEARCH_FIELD_LENGTH];
        char *pstr;
        int pos_first_non_blank;
+       size_t len;
 
        strncpy(search_string, string2, MAX_SEARCH_FIELD_LENGTH);
        search_string[MAX_SEARCH_FIELD_LENGTH - 1] = '\0';
@@ -84,7 +85,11 @@ int strstr_icase_blank(const char * const string1, const char * const string2)
                        }
                }
        }
-       strncpy(search_string, cmp_line, strlen(search_string));
+       len = strlen(search_string);
+       if (len > sizeof(search_string) - 1)
+               len = sizeof(search_string) - 1;
+       strncpy(search_string, cmp_line, len);
+       search_string[len] = '\0';
 
        position = 0;
        while (position < strlen(string1))