Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ca9148

Browse files
committed
Add missing error checking in readdir() loops.
1 parentc58071a commit0ca9148

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

‎src/port/copydir.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*as a service.
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.10 2004/12/31 22:03:53 pgsql Exp $
14+
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.11 2005/03/24 02:11:20 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -56,6 +56,7 @@ copydir(char *fromdir, char *todir)
5656
return-1;
5757
}
5858

59+
errno=0;
5960
while ((xlde=readdir(xldir))!=NULL)
6061
{
6162
snprintf(fromfl,MAXPGPATH,"%s/%s",fromdir,xlde->d_name);
@@ -68,6 +69,24 @@ copydir(char *fromdir, char *todir)
6869
FreeDir(xldir);
6970
return-1;
7071
}
72+
errno=0;
73+
}
74+
#ifdefWIN32
75+
76+
/*
77+
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
78+
* not in released version
79+
*/
80+
if (GetLastError()==ERROR_NO_MORE_FILES)
81+
errno=0;
82+
#endif
83+
if (errno)
84+
{
85+
ereport(WARNING,
86+
(errcode_for_file_access(),
87+
errmsg("could not read directory \"%s\": %m",fromdir)));
88+
FreeDir(xldir);
89+
return-1;
7190
}
7291

7392
FreeDir(xldir);

‎src/port/dirmod.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*Win32 (NT, Win2k, XP).replace() doesn't work on Win95/98/Me.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.36 2005/02/22 04:43:16 momjian Exp $
13+
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.37 2005/03/24 02:11:20 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -326,10 +326,19 @@ fnames(char *path)
326326

327327
dir=opendir(path);
328328
if (dir==NULL)
329+
{
330+
#ifndefFRONTEND
331+
elog(WARNING,"could not open directory \"%s\": %m",path);
332+
#else
333+
fprintf(stderr,_("could not open directory \"%s\": %s\n"),
334+
path,strerror(errno));
335+
#endif
329336
returnNULL;
337+
}
330338

331339
filenames= (char**)palloc(fnsize*sizeof(char*));
332340

341+
errno=0;
333342
while ((file=readdir(dir))!=NULL)
334343
{
335344
if (strcmp(file->d_name,".")!=0&&strcmp(file->d_name,"..")!=0)
@@ -342,6 +351,25 @@ fnames(char *path)
342351
}
343352
filenames[numnames++]=pstrdup(file->d_name);
344353
}
354+
errno=0;
355+
}
356+
#ifdefWIN32
357+
358+
/*
359+
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
360+
* not in released version
361+
*/
362+
if (GetLastError()==ERROR_NO_MORE_FILES)
363+
errno=0;
364+
#endif
365+
if (errno)
366+
{
367+
#ifndefFRONTEND
368+
elog(WARNING,"could not read directory \"%s\": %m",path);
369+
#else
370+
fprintf(stderr,_("could not read directory \"%s\": %s\n"),
371+
path,strerror(errno));
372+
#endif
345373
}
346374

347375
filenames[numnames]=NULL;
@@ -434,7 +462,8 @@ rmtree(char *path, bool rmtopdir)
434462
#ifndefFRONTEND
435463
elog(WARNING,"could not remove file or directory \"%s\": %m",filepath);
436464
#else
437-
fprintf(stderr,_("could not remove file or directory \"%s\": %s\n"),filepath,strerror(errno));
465+
fprintf(stderr,_("could not remove file or directory \"%s\": %s\n"),
466+
filepath,strerror(errno));
438467
#endif
439468
fnames_cleanup(filenames);
440469
return false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp