fix CID# 10542

This commit is contained in:
cwu 2013-02-13 12:03:21 -08:00
parent c3924bb072
commit 0fdaab06f8

View file

@ -990,13 +990,15 @@ static int sigtool_scandir (const char *dirname, int hex_output)
int ret = CL_CLEAN, desc;
cli_ctx *ctx;
fname = NULL;
if ((dd = opendir (dirname)) != NULL) {
while ((dent = readdir (dd))) {
if (dent->d_ino) {
if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
/* build the full name */
fname = (char *) cli_calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));
if(!fname)
return -1;
sprintf (fname, "%s"PATHSEP"%s", dirname, dent->d_name);
/* stat the file */
@ -1016,12 +1018,14 @@ static int sigtool_scandir (const char *dirname, int hex_output)
dir = cli_gentemp (tmpdir);
if(!dir) {
printf("cli_gentemp() failed\n");
free(fname);
closedir (dd);
return -1;
}
if (mkdir (dir, 0700)) {
printf ("Can't create temporary directory %s\n", dir);
free(fname);
closedir (dd);
free(dir);
return CL_ETMPDIR;
@ -1029,12 +1033,14 @@ static int sigtool_scandir (const char *dirname, int hex_output)
if ((desc = open (fname, O_RDONLY|O_BINARY)) == -1) {
printf ("Can't open file %s\n", fname);
free(fname);
closedir (dd);
free(dir);
return 1;
}
if(!(ctx = convenience_ctx(desc))) {
free(fname);
close(desc);
closedir(dd);
free(dir);
@ -1046,6 +1052,7 @@ static int sigtool_scandir (const char *dirname, int hex_output)
cli_rmdirs (dir);
free (dir);
closedir (dd);
free(fname);
return ret;
}