Re: compress: funopen error handling

2015-01-31 Thread Todd C. Miller
On Sat, 31 Jan 2015 16:40:48 +0100, Tobias Stoeckmann wrote:

 this diff adds error handling for funopen() failure.  I have also fixed
 a whitespace issue for proper intendation.

OK millert@

 - todd



compress: funopen error handling

2015-01-31 Thread Tobias Stoeckmann
Hi,

this diff adds error handling for funopen() failure.  I have also fixed
a whitespace issue for proper intendation.


Tobias

Index: usr.bin/compress/zopen.c
===
RCS file: /cvs/src/usr.bin/compress/zopen.c,v
retrieving revision 1.19
diff -u -p -r1.19 zopen.c
--- usr.bin/compress/zopen.c16 Jan 2015 06:40:06 -  1.19
+++ usr.bin/compress/zopen.c31 Jan 2015 15:36:23 -
@@ -278,7 +278,7 @@ zwrite(void *cookie, const char *wbp, in
/* Secondary hash (after G. Knott). */
disp = zs-zs_hsize_reg - i;
if (i == 0)
-   disp = 1;
+   disp = 1;
 probe: if ((i -= disp)  0)
i += zs-zs_hsize_reg;
 
@@ -738,6 +738,7 @@ cl_hash(struct s_zstate *zs, count_int c
 FILE *
 zopen(const char *name, const char *mode, int bits)
 {
+   FILE *fp;
int fd;
void *cookie;
if ((fd = open(name, (*mode=='r'? O_RDONLY:O_WRONLY|O_CREAT),
@@ -747,8 +748,13 @@ zopen(const char *name, const char *mode
close(fd);
return NULL;
}
-   return funopen(cookie, (*mode == 'r'?zread:NULL),
-   (*mode == 'w'?zwrite:NULL), NULL, zclose);
+   if ((fp = funopen(cookie, (*mode == 'r'?zread:NULL),
+   (*mode == 'w'?zwrite:NULL), NULL, zclose)) == NULL) {
+   close(fd);
+   free(cookie);
+   return NULL;
+   }
+   return fp;
 }
 
 void *