Re: rpki-client don't clobber errno in mkpath

2021-05-06 Thread Theo de Raadt
I'm confused.

Who has a free() that clobbers errno?


Claudio Jeker  wrote:

> Noticed while looking at the same version in rsync. free() may clobber
> errno so better save the value before calling free().
> Also update the comment, remove all those arguments I removed :)
> 
> -- 
> :wq Claudio
> 
> Index: mkdir.c
> ===
> RCS file: /cvs/src/usr.sbin/rpki-client/mkdir.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 mkdir.c
> --- mkdir.c   29 Mar 2021 04:01:17 -  1.6
> +++ mkdir.c   6 May 2021 16:41:16 -
> @@ -39,15 +39,13 @@
>  
>  /*
>   * mkpath -- create directories.
> - *   path - path
> - *   mode - file mode of terminal directory
> - *   dir_mode - file mode of intermediate directories
> + *   dir - path to create directories for
>   */
>  int
>  mkpath(const char *dir)
>  {
>   char *path, *slash;
> - int done;
> + int done, save_errno;
>  
>   if ((path = strdup(dir)) == NULL)
>   return -1;
> @@ -61,7 +59,9 @@ mkpath(const char *dir)
>   *slash = '\0';
>  
>   if (mkdir(path, 0755) == -1 && errno != EEXIST) {
> + save_errno = errno;
>   free(path);
> + errno = save_errno;
>   return -1;
>   }
>  
> 



rpki-client don't clobber errno in mkpath

2021-05-06 Thread Claudio Jeker
Noticed while looking at the same version in rsync. free() may clobber
errno so better save the value before calling free().
Also update the comment, remove all those arguments I removed :)

-- 
:wq Claudio

Index: mkdir.c
===
RCS file: /cvs/src/usr.sbin/rpki-client/mkdir.c,v
retrieving revision 1.6
diff -u -p -r1.6 mkdir.c
--- mkdir.c 29 Mar 2021 04:01:17 -  1.6
+++ mkdir.c 6 May 2021 16:41:16 -
@@ -39,15 +39,13 @@
 
 /*
  * mkpath -- create directories.
- * path - path
- * mode - file mode of terminal directory
- * dir_mode - file mode of intermediate directories
+ * dir - path to create directories for
  */
 int
 mkpath(const char *dir)
 {
char *path, *slash;
-   int done;
+   int done, save_errno;
 
if ((path = strdup(dir)) == NULL)
return -1;
@@ -61,7 +59,9 @@ mkpath(const char *dir)
*slash = '\0';
 
if (mkdir(path, 0755) == -1 && errno != EEXIST) {
+   save_errno = errno;
free(path);
+   errno = save_errno;
return -1;
}