[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mgp-users 01235] Please add system() patch



I submitted a patch to detect failures of the system() calls
in mgp.c, which hasn't made it into any version yet.  IMHO,
this is very important for "production code", so please apply
it.

The latest version of the patch, updated for 1.10a, is included
below. It makes use of the #define'd macro WEXITSTATUS, which
is defined on Linux in stdlib.h.  My version of Solaris doesn't
have a (standard) C compiler, so I'm not sure where the definition
would be found there, but I'd like to think it would be in the
same place.  Can somebody tell us?  

Thanks,

-Tim
*------------------------------------------------------------*
| Tim Maher (206) 781-UNIX  (866) DOC-PERL  (866) DOC-UNIX   |
| tim(AT)Consultix-Inc.Com  TeachMeUnix.Com  TeachMePerl.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
|  Watch for my Book: "Minimal Perl for Shell Programmers"   |
*------------------------------------------------------------*

44a45,47
> /* tfm mod; for WEXITSTATUS on Linux */
> #include <stdlib.h>
> 
512c515,520
< 		system(buf);	/*XXX security hole*/
---
> 		/* <tfm modifications> */
> 		int err;
> 		err=system(buf);  /*XXX security hole*/
> 		exit_on_failure(err,buf);
> 		/* </tfm modifications> */
> 
518c526,529
< 		system(buf);	/*XXX security hole*/
---
> 		/* <tfm modifications> */
> 		err=system(buf);  /*XXX security hole*/
> 		exit_on_failure(err,buf);
> 		/* </tfm modifications> */
1365a1377,1406
> 
> /* <tfm modifications> */
> int exit_on_failure(err, command)
>   int err;
>   char *command;
> {
> /* Tim Maher, Mon Jun 23 06:01:25 PDT 2003
> 
>   Wrote this because I spent the whole weekend trying to
>   figure out why my image files were turning out corrupted,
>   and eventually noticed the lack of error checking on system()
>   calls, which was part of the problem.
> */
> 
>     if (err == -1 ) {
>       fprintf(stderr, "\nsystem() failed for %s\n", command);
>       exit (210);     /* exit-val probably unused elsewhere */
>     }
>     else {
>       err=WEXITSTATUS(err);
>       if (err > 0) {
>         fprintf(stderr,
> 		"\nCommand '%s' failed, with code %d\n", command, err);
>         exit (err);
>       }
>       else  {	/* no error */
>           return 1;
>       }
>    }
> }