Fixed buffer overflow
This commit is contained in:
		@@ -54,24 +54,32 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Construct the full path
 | 
			
		||||
    char fullpath[PATH_MAX];
 | 
			
		||||
    snprintf(fullpath, PATH_MAX, "%s/%s", path, entry->d_name);
 | 
			
		||||
    char *fullpath = NULL;
 | 
			
		||||
    if (asprintf(&fullpath, "%s/%s", path, entry->d_name) == -1 ||
 | 
			
		||||
        fullpath == NULL) {
 | 
			
		||||
      perror("asprintf");
 | 
			
		||||
      success = 0;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Stat the entry to check if it's a regular file
 | 
			
		||||
    struct stat entry_stat;
 | 
			
		||||
    if (lstat(fullpath, &entry_stat) == -1) {
 | 
			
		||||
      perror("lstat");
 | 
			
		||||
      success = 0;
 | 
			
		||||
      free(fullpath);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Only process regular files
 | 
			
		||||
    if (!S_ISREG(entry_stat.st_mode)) {
 | 
			
		||||
      free(fullpath);
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Try to open and immediately close the file
 | 
			
		||||
    int fd = open(fullpath, O_RDONLY);
 | 
			
		||||
    free(fullpath);
 | 
			
		||||
    if (fd == -1) {
 | 
			
		||||
      perror("open");
 | 
			
		||||
      success = 0;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user