s3/smbd: Fix string buffer overflow causing heap corruption
authorSteven Danneman <steven.danneman@isilon.com>
Sat, 30 Jan 2010 21:29:23 +0000 (13:29 -0800)
committerSteven Danneman <steven.danneman@isilon.com>
Sat, 30 Jan 2010 21:38:31 +0000 (13:38 -0800)
The destname malloc size was not taking into account the 1 extra byte
needed if a string without a leading '/' was passed in and that slash
was added.

This would cause the '\0' byte to be written past the end of the
malloced destname string and corrupt whatever heap memory was there.

This problem would be hit if a share name was given in smb.conf without
a leading '/' and if it was the exact size of the allocated STRDUP memory
which in some implementations of malloc is a power of 2.

source3/smbd/service.c

index 48593446e2f8e0b131faa95345291885656fd993..e8775ffd7b53be983fcfa128ddbf7951f7a98e48 100644 (file)
@@ -60,7 +60,8 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath)
                return false;
        }
 
-       destname = SMB_STRDUP(connectpath);
+       /* Allocate for strlen + '\0' + possible leading '/' */
+       destname = SMB_MALLOC(strlen(connectpath) + 2);
        if (!destname) {
                return false;
        }