===================================================================
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
+-- Copyright (C) 2004-2017, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -528,6 +528,10 @@
begin
Local_Get_Current_Dir (Buffer'Address, Path_Len'Address);
+ if Path_Len = 0 then
+ raise Use_Error with "current directory does not exist";
+ end if;
+
-- We need to resolve links because of RM A.16(47), which requires
-- that we not return alternative names for files.
===================================================================
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
+-- Copyright (C) 1998-2017, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -29,6 +29,7 @@
-- --
------------------------------------------------------------------------------
+with Ada.IO_Exceptions;
with Ada.Characters.Handling;
with Ada.Strings.Fixed;
@@ -573,6 +574,11 @@
begin
Local_Get_Current_Dir (Buffer'Address, Path_Len'Address);
+ if Path_Len = 0 then
+ raise Ada.IO_Exceptions.Use_Error
+ with "current directory does not exist";
+ end if;
+
Last :=
(if Dir'Length > Path_Len then Dir'First + Path_Len - 1 else Dir'Last);
===================================================================
@@ -6,7 +6,7 @@
* *
* C Implementation File *
* *
- * Copyright (C) 1992-2015, Free Software Foundation, Inc. *
+ * Copyright (C) 1992-2017, Free Software Foundation, Inc. *
* *
* GNAT is free software; you can redistribute it and/or modify it under *
* terms of the GNU General Public License as published by the Free Soft- *
@@ -613,7 +613,16 @@
WS2SC (dir, wdir, GNAT_MAX_PATH_LEN);
#else
- getcwd (dir, *length);
+ char* result = getcwd (dir, *length);
+ /* If the current directory does not exist, set length = 0
+ to indicate error. That can't happen on windows, where
+ you can't delete a directory if it is the current
+ directory of some process. */
+ if (!result)
+ {
+ *length = 0;
+ return;
+ }
#endif
*length = strlen (dir);
===================================================================
@@ -1550,6 +1550,10 @@
begin
Get_Current_Dir (Buffer'Address, Path_Len'Address);
+ if Path_Len = 0 then
+ raise Program_Error;
+ end if;
+
if Buffer (Path_Len) /= Directory_Separator then
Path_Len := Path_Len + 1;
Buffer (Path_Len) := Directory_Separator;
===================================================================
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
+-- Copyright (C) 1995-2017, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -2191,6 +2191,10 @@
begin
Get_Current_Dir (Buffer'Address, Path_Len'Address);
+ if Path_Len = 0 then
+ raise Program_Error;
+ end if;
+
if Buffer (Path_Len) /= Directory_Separator then
Path_Len := Path_Len + 1;
Buffer (Path_Len) := Directory_Separator;