Skip to contentSkip to conversation

Possible buffer overflow

PATCH In review Matthias Koenig 3 participants 3 messages Nov 30, 2006 – Dec 1, 2006 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Possible buffer overflow

Hi,

There seems to be a possible buffer overflow in modules/mount_afs.c. strncat(dest, src, n) uses at most n chars from src. n is not the size of dest. Patch below.

Regards,
Matthias

mount_afs.c +2 -2
@@ -36,8 +36,8 @@
 	char dest[PATH_MAX * 2];
 
 	strcpy(dest, root);	/* Convert the name to a mount point. */
-	strncat(dest, "/", sizeof(dest));
-	strncat(dest, name, sizeof(dest));
+	strncat(dest, "/", sizeof(dest)-strlen(dest)-1);
+	strncat(dest, name, sizeof(dest)-strlen(dest)-1);
 
 	/* remove trailing slash (http://bugs.debian.org/141775) */
 	if (dest[strlen(dest)-1] == '/')
#1 lore raw

==> On Thu, 30 Nov 2006 18:06:43 +0100, Matthias Koenig <[email protected]> said:

Matthias> Hi,
Matthias> There seems to be a possible buffer overflow in modules/mount_afs.c. Matthias> strncat(dest, src, n) uses at most n chars from src. n is not the Matthias> size of dest. Patch below.

The fix seems correct to me. Have you actually seen a problem in the wild? I wonder why the dest string is twice the maximum path length; that doesn't make a whole lot of sense. Perhaps we should fix that while we're in here.

-Jeff

Quoted 13 lines
mount_afs.c +2 -2
@@ -36,8 +36,8 @@
 	char dest[PATH_MAX * 2];
 
 	strcpy(dest, root);	/* Convert the name to a mount point. */
-	strncat(dest, "/", sizeof(dest));
-	strncat(dest, name, sizeof(dest));
+	strncat(dest, "/", sizeof(dest)-strlen(dest)-1);
+	strncat(dest, name, sizeof(dest)-strlen(dest)-1);
 
 	/* remove trailing slash (http://bugs.debian.org/141775) */
 	if (dest[strlen(dest)-1] == '/')
maintainer
#2 lore raw
Quoted 11 lines · Jeff Moyer

==> On Thu, 30 Nov 2006 18:06:43 +0100, Matthias Koenig <[email protected]> said:

Matthias> Hi,
Matthias> There seems to be a possible buffer overflow in modules/mount_afs.c. Matthias> strncat(dest, src, n) uses at most n chars from src. n is not the Matthias> size of dest. Patch below.

The fix seems correct to me. Have you actually seen a problem in the wild? I wonder why the dest string is twice the maximum path length; that doesn't make a whole lot of sense. Perhaps we should fix that while we're in here.

Yes, that array does seem to be excessive.
I was thinking that it would be better to calculate the length, check it and then do the copy.

Quoted 21 lines

-Jeff

mount_afs.c line 43

Quoted 13 lines
mount_afs.c +2 -2
@@ -36,8 +36,8 @@
 	char dest[PATH_MAX * 2];
 
 	strcpy(dest, root);	/* Convert the name to a mount point. */
-	strncat(dest, "/", sizeof(dest));
-	strncat(dest, name, sizeof(dest));
+	strncat(dest, "/", sizeof(dest)-strlen(dest)-1);
+	strncat(dest, name, sizeof(dest)-strlen(dest)-1);
 
 	/* remove trailing slash (http://bugs.debian.org/141775) */
 	if (dest[strlen(dest)-1] == '/')

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs