Created
October 7, 2013 03:43
-
-
Save harshavardhana/6862240 to your computer and use it in GitHub Desktop.
Closedir dirstream corruption check during directory crawling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <dirent.h> | |
#define _FILE_OFFSET_BITS 64 | |
int main() | |
{ | |
DIR *dir = NULL; | |
struct dirent *ptr; | |
struct dirent *result; | |
int fd = 0; | |
dir = opendir("."); | |
ptr = malloc(sizeof(*ptr) + (PATH_MAX + 1)); | |
if (ptr == NULL) { | |
fprintf (stderr, "Malloc error"); | |
closedir(dir); | |
return -1; | |
} | |
while ((readdir64_r(dir, ptr, &result) == 0) && (result != NULL)) { | |
if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, "..")) | |
continue; | |
fprintf (stdout, "I am here -> %s\n", ptr->d_name); | |
} | |
closedir(dir); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment