Re: [BUG] Segmentation fault when copy symlink with checked "Stable Symlinks"



Hi Leonard,

On Sat, 2005-09-17 at 12:59 +0200, Leonard den Ottolander wrote:
> Hi,
> 
> On Sat, 2005-09-17 at 12:48 +0200, Leonard den Ottolander wrote:
> > Hi Jindrich,
> > 
> > On Tue, 2005-09-13 at 13:07 +0200, Jindrich Novy wrote:
> > > -           my_second = resolve_symlinks (second);
> > > -           if (my_second == NULL) {
> > > -               g_free (my_first);
> > > +           if (my_second == NULL)
> > >                 return buf;
> > > -           }
> > 
> > Why do you drop the g_free of my_first here?
> 
> It seems like the whole if (j) block is redundant. Right?

Yeah, the whole if (j) part is pretty bogus and can be removed.
Apparently there's no leakage of my_first because the if (my_second ==
NULL) in the if (j) condition never succeed as it's checked already
before the loop. So we can remove it safely.

Thanks for the review. The changelog entries and separate patches are
comming up.

2005-09-17  Jindrich Novy  <jnovy redhat com>

	* util.c: Fixed segfault in diff_two_paths() when symlink
	is copied with "Stable Symlinks" checked.
	* file.c: Fixed off-by-one indexing error in make_symlink()
	causing generation of dangled symlinks.

Cheers,
Jindrich

-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
(o_                                                           _o)
//\      The worst evil in the world is refusal to think.     //\
V_/_                                                         _\_V

--- mc-4.6.1/src/util.c.jn	2005-05-27 16:19:18.000000000 +0200
+++ mc-4.6.1/src/util.c	2005-09-17 13:58:47.000000000 +0200
@@ -1140,22 +1140,20 @@
  * as needed up in first and then goes down using second */
 char *diff_two_paths (const char *first, const char *second) 
 {
-    char *p, *q, *r, *s, *buf = 0;
+    char *p, *q, *r, *s, *buf = NULL;
     int i, j, prevlen = -1, currlen;
     char *my_first = NULL, *my_second = NULL;
     
     my_first = resolve_symlinks (first);
     if (my_first == NULL)
         return NULL;
+    my_second = resolve_symlinks (second);
+    if (my_second == NULL) {
+	g_free (my_first);
+	return NULL;
+    }
     for (j = 0; j < 2; j++) {
 	p = my_first;
-	if (j) {
-	    my_second = resolve_symlinks (second);
-	    if (my_second == NULL) {
-		g_free (my_first);
-	        return buf;
-	    }
-	}
 	q = my_second;
 	for (;;) {
 	    r = strchr (p, PATH_SEP);
--- mc-4.6.1/src/file.c.jn	2005-05-27 16:19:18.000000000 +0200
+++ mc-4.6.1/src/file.c	2005-09-17 13:58:20.000000000 +0200
@@ -382,7 +382,7 @@
 	const char *r = strrchr (src_path, PATH_SEP);
 
 	if (r) {
-	    p = g_strndup (src_path, r - src_path);
+	    p = g_strndup (src_path, r - src_path + 1);
 	    if (*dst_path == PATH_SEP)
 		q = g_strdup (dst_path);
 	    else


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