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

Re: [JOB] libcflow-perl



On Sat, Jul 28, 2001 at 01:05:41PM +0200, Robert Bihlmeyer wrote:
> James Morrison <rocketmail_com@rocketmail.com> writes:
> 
> > This one was easy.  The PATH_MAX usage was char name[PATH_MAX];
> > I replaced it with char *name; then it compiles fine and it should
> > work
> > since any instance of name uses a length completely independent of
> > PATH_MAX
> 
> E.g.
>                    strncpy(name, namep, len);
> 
> You did malloc name before that, right? (... and free it after use)

The full code is:

                   namep = SvPV(ST(arg), len);
                   strncpy(name, namep, len);
                   name[len] = '\0';
                   if (0 == strcmp("-", name)) {
                      fp = fdopen(STDIN_FILENO, "r");
                   } else {
                      fp = fopen(name, "r");
                   }
                   if ((FILE *)0 == fp) {
                      croak("fopen \"%s\": %s", name, strerror(errno));
                   }

I suggets to just strdup it.  Maybe namep can be used instead name, and the
variable name removed, but I am not sure as I have no clear idea what SvPV
does (I think it is used to extract a perl scalar argument and interpret it
as a C string.  As name is not changed in the function, replacing it with
namep throughout and removing name seems to be sane.  The goal of the above
code seems to be to truncate namep to PATH_MAX characters, which is really
not necessary.)

If copying the string is required, it should be `name = strdup (namep);'
[mmmh. I think strdup does not exist on some systems, for portability, a
malloc(strlen(Namep)) and strcpy might be required].

So what about:

--- Cflow.xs.old	Sat Jul 28 14:50:41 2001
+++ Cflow.xs	Sat Jul 28 14:51:47 2001
@@ -9,7 +9,6 @@
 #endif
 
 #include <errno.h> /* errno, ENOENT */
-#include <limits.h> /* PATH_MAX */
 #include <stdio.h> /* FILE, fdopen, fopen, fread, fclose, sprintf */
 #include <string.h> /* strncpy, strcmp, strerror */
 #include <sys/types.h> /* size_t */
@@ -155,8 +154,7 @@
 
 		while (arg < items) {
 		   size_t len;
-                   char *namep;
-		   char name[PATH_MAX];
+                   char *name;
 		   FILE *fp = (FILE *)0;
 		   cflowrec flow;
 
@@ -164,9 +162,7 @@
 		      croak("Usage: find(CODEREF, [CODEREF], FILE [...])");
 		   }
 
-                   namep = SvPV(ST(arg), len);
-		   strncpy(name, namep, len);
-		   name[len] = '\0';
+                   name = SvPV(ST(arg), len);
 		   if (0 == strcmp("-", name)) {
 		      fp = fdopen(STDIN_FILENO, "r");
 		   } else {

(If someone could test and file a bug report with the patch, that would be
good.)

Thanks,
Marcus



-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de



Reply to: