|
16 | 16 | * of this software and associated documentation files (the "Software"), to deal |
17 | 17 | * in the Software without restriction, including without limitation the rights |
18 | 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
19 | | - * copies of the Software, and to permit persons to whom the Software is |
| 19 | + * copies of the Software, and to permit persons to whom the Softwaref is |
20 | 20 | * furnished to do so, subject to the following conditions: |
21 | 21 | * |
22 | 22 | * The above copyright notice and this permission notice shall be included in |
@@ -865,22 +865,49 @@ bool rm_recursive(const char* const path) { |
865 | 865 | void build_mount_point(char* mount_dir, const char* const argv0, char const* const temp_base, const size_t templen) { |
866 | 866 | const size_t maxnamelen = 6; |
867 | 867 |
|
| 868 | + // Check for NULL argv0 |
| 869 | + if (argv0 == NULL) { |
| 870 | + fprintf(stderr, "Error: argv0 is NULL\n"); |
| 871 | + return; |
| 872 | + } |
| 873 | + |
868 | 874 | // need to copy argv0 as it's a const value, basename intends to modify it |
869 | 875 | char* argv0_copy = strdup(argv0); |
| 876 | + if (argv0_copy == NULL) { |
| 877 | + fprintf(stderr, "Error: strdup failed\n"); |
| 878 | + return; |
| 879 | + } |
| 880 | + |
870 | 881 | char* path_basename = basename(argv0_copy); |
871 | | - free(argv0_copy); |
| 882 | + if (path_basename == NULL) { |
| 883 | + free(argv0_copy); |
| 884 | + fprintf(stderr, "Error: basename returned NULL\n"); |
| 885 | + return; |
| 886 | + } |
872 | 887 |
|
873 | 888 | size_t namelen = strlen(path_basename); |
874 | 889 | // limit length of tempdir name |
875 | 890 | if (namelen > maxnamelen) { |
876 | 891 | namelen = maxnamelen; |
877 | 892 | } |
878 | 893 |
|
| 894 | + // Ensure mount_dir has enough space |
| 895 | + size_t required_length = templen + 8 + namelen + 6 + 1; // +1 for null terminator |
| 896 | + if (strlen(temp_base) + required_length > sizeof(mount_dir)) { |
| 897 | + free(argv0_copy); |
| 898 | + fprintf(stderr, "Error: mount_dir does not have enough space\n"); |
| 899 | + return; |
| 900 | + } |
| 901 | + |
879 | 902 | strcpy(mount_dir, temp_base); |
880 | 903 | strncpy(mount_dir + templen, "/.mount_", 8); |
881 | 904 | strncpy(mount_dir + templen + 8, path_basename, namelen); |
882 | 905 | strncpy(mount_dir + templen + 8 + namelen, "XXXXXX", 6); |
883 | | - mount_dir[templen + 8 + namelen + 6] = 0; // null terminate destination |
| 906 | + |
| 907 | + // Null terminate the destination |
| 908 | + mount_dir[templen + 8 + namelen + 6] = '\0'; // null terminate destination |
| 909 | + |
| 910 | + free(argv0_copy); |
884 | 911 | } |
885 | 912 |
|
886 | 913 | int fusefs_main(int argc, char* argv[], void (* mounted)(void)) { |
|
0 commit comments