]> git.alsa-project.org Git - alsa-tools.git/commitdiff
envy24control: fix memory access errors in profiles
authorAndreas Persson <andreasp56@outlook.com>
Sat, 29 Mar 2025 12:20:15 +0000 (13:20 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 9 Apr 2025 09:44:37 +0000 (11:44 +0200)
Fix two memory errors in the profiles parser: an invalid read and a
"source and destination overlap in strncpy" warning.

When the profiles page is initialized it fetches the profile names from
the profiles file. When a profile wasn't defined in the file, the parser
made invalid reads outside the buffer.

Closes: https://github.com/alsa-project/alsa-tools/pull/34
Signed-off-by: Andreas Persson <andreasp56@outlook.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
envy24control/profiles.c

index a67ef0c6a6cc7e2f6cb9b4431917c4d11caf875f..9e5cde1dd81056fcb66ab7e6224b93072cf7f9b8 100644 (file)
@@ -96,7 +96,9 @@ int get_file_size(const char * const filename)
 {
        struct stat file_status;
 
-       strncpy(filename_without_tilde, filename, MAX_FILE_NAME_LENGTH);
+       if (filename_without_tilde != filename) {
+               strncpy(filename_without_tilde, filename, MAX_FILE_NAME_LENGTH);
+       }
        filename_without_tilde[MAX_FILE_NAME_LENGTH - 1] = '\0';
        subst_tilde_in_filename(filename_without_tilde);
        if (stat(filename_without_tilde, &file_status) < 0) {
@@ -472,7 +474,8 @@ int get_pos_name_header_from_card(const char * const buffer, const int profile_n
        char place_holder;
        int pos_card_begin, pos_card_end, pos_name_header;
 
-       pos_card_begin = get_card_begin(buffer, profile_number, card_number);
+       if ((pos_card_begin = get_card_begin(buffer, profile_number, card_number)) < 0)
+               return pos_card_begin;
        pos_card_end = get_card_end(buffer, profile_number, card_number);
        place_holder = PLACE_HOLDER_STR;
        strncpy(header, PROFILE_NAME_TEMPL, MAX_SEARCH_FIELD_LENGTH);