Fix path copy error and add more logs. (#10324)

Since we didn't copy the null terminator to temp_filepath, dirname could return the wrong result.
This commit is contained in:
chenyang8094 2022-02-22 16:09:34 +08:00 committed by GitHub
parent 65e4bce0e7
commit 4916d79fbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -226,7 +226,7 @@ int checkSingleAof(char *aof_filename, char *aof_filepath, int last_file, int fi
FILE *fp = fopen(aof_filepath, "r+");
if (fp == NULL) {
printf("Cannot open file: %s, aborting...\n", aof_filename);
printf("Cannot open file %s: %s, aborting...\n", aof_filepath, strerror(errno));
exit(1);
}
@ -336,7 +336,7 @@ int checkSingleAof(char *aof_filename, char *aof_filepath, int last_file, int fi
int fileIsRDB(char *filepath) {
FILE *fp = fopen(filepath, "r");
if (fp == NULL) {
printf("Cannot open file: %s\n", filepath);
printf("Cannot open file %s: %s\n", filepath, strerror(errno));
exit(1);
}
@ -372,7 +372,7 @@ int fileIsManifest(char *filepath) {
int is_manifest = 0;
FILE *fp = fopen(filepath, "r");
if (fp == NULL) {
printf("Cannot open file: %s\n", filepath);
printf("Cannot open file %s: %s\n", filepath, strerror(errno));
exit(1);
}
@ -554,7 +554,7 @@ int redis_check_aof_main(int argc, char **argv) {
}
/* In the glibc implementation dirname may modify their argument. */
memcpy(temp_filepath, filepath, strlen(filepath));
memcpy(temp_filepath, filepath, strlen(filepath) + 1);
dirpath = dirname(temp_filepath);
/* Select the corresponding verification method according to the input file type. */