Author: jerry
Date: 2005-10-18 02:37:13 +0000 (Tue, 18 Oct 2005)
New Revision: 11135

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11135

Log:
should fix seg fault in addprinter code reported by Marcin.  Allocate memory in 
convert_printer_info() if necessary
Modified:
   branches/SAMBA_3_0/source/rpc_server/srv_spoolss_nt.c
   branches/SAMBA_3_0_RELEASE/source/rpc_server/srv_spoolss_nt.c
   trunk/source/rpc_server/srv_spoolss_nt.c


Changeset:
Modified: branches/SAMBA_3_0/source/rpc_server/srv_spoolss_nt.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_server/srv_spoolss_nt.c       2005-10-18 
02:36:16 UTC (rev 11134)
+++ branches/SAMBA_3_0/source/rpc_server/srv_spoolss_nt.c       2005-10-18 
02:37:13 UTC (rev 11135)
@@ -1729,20 +1729,29 @@
 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
                                NT_PRINTER_INFO_LEVEL *printer, uint32 level)
 {
-       BOOL ret = True;
+       BOOL ret;
 
        switch (level) {
                case 2:
-                       /* printer->info_2  is already a valid printer */
+                       /* allocate memory if needed.  Messy because 
+                          convert_printer_info is used to update an existing 
+                          printer or build a new one */
+
+                       if ( !printer->info_2 ) {
+                               printer->info_2 = TALLOC_ZERO_P( printer, 
NT_PRINTER_INFO_LEVEL_2 );
+                               if ( !printer->info_2 ) {
+                                       DEBUG(0,("convert_printer_info: 
talloc() failed!\n"));
+                                       return False;
+                               }
+                       }
+
                        ret = uni_2_asc_printer_info_2(uni->info_2, 
printer->info_2);
                        printer->info_2->setuptime = time(NULL);
 
-                       break;
-               default:
-                       break;
+                       return ret;
        }
 
-       return ret;
+       return False;
 }
 
 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL 
*uni,

Modified: branches/SAMBA_3_0_RELEASE/source/rpc_server/srv_spoolss_nt.c
===================================================================
--- branches/SAMBA_3_0_RELEASE/source/rpc_server/srv_spoolss_nt.c       
2005-10-18 02:36:16 UTC (rev 11134)
+++ branches/SAMBA_3_0_RELEASE/source/rpc_server/srv_spoolss_nt.c       
2005-10-18 02:37:13 UTC (rev 11135)
@@ -1729,20 +1729,29 @@
 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
                                NT_PRINTER_INFO_LEVEL *printer, uint32 level)
 {
-       BOOL ret = True;
+       BOOL ret;
 
        switch (level) {
                case 2:
-                       /* printer->info_2  is already a valid printer */
+                       /* allocate memory if needed.  Messy because 
+                          convert_printer_info is used to update an existing 
+                          printer or build a new one */
+
+                       if ( !printer->info_2 ) {
+                               printer->info_2 = TALLOC_ZERO_P( printer, 
NT_PRINTER_INFO_LEVEL_2 );
+                               if ( !printer->info_2 ) {
+                                       DEBUG(0,("convert_printer_info: 
talloc() failed!\n"));
+                                       return False;
+                               }
+                       }
+
                        ret = uni_2_asc_printer_info_2(uni->info_2, 
printer->info_2);
                        printer->info_2->setuptime = time(NULL);
 
-                       break;
-               default:
-                       break;
+                       return ret;
        }
 
-       return ret;
+       return False;
 }
 
 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL 
*uni,

Modified: trunk/source/rpc_server/srv_spoolss_nt.c
===================================================================
--- trunk/source/rpc_server/srv_spoolss_nt.c    2005-10-18 02:36:16 UTC (rev 
11134)
+++ trunk/source/rpc_server/srv_spoolss_nt.c    2005-10-18 02:37:13 UTC (rev 
11135)
@@ -1729,20 +1729,29 @@
 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
                                NT_PRINTER_INFO_LEVEL *printer, uint32 level)
 {
-       BOOL ret = True;
+       BOOL ret;
 
        switch (level) {
                case 2:
-                       /* printer->info_2  is already a valid printer */
+                       /* allocate memory if needed.  Messy because 
+                          convert_printer_info is used to update an existing 
+                          printer or build a new one */
+
+                       if ( !printer->info_2 ) {
+                               printer->info_2 = TALLOC_ZERO_P( printer, 
NT_PRINTER_INFO_LEVEL_2 );
+                               if ( !printer->info_2 ) {
+                                       DEBUG(0,("convert_printer_info: 
talloc() failed!\n"));
+                                       return False;
+                               }
+                       }
+
                        ret = uni_2_asc_printer_info_2(uni->info_2, 
printer->info_2);
                        printer->info_2->setuptime = time(NULL);
 
-                       break;
-               default:
-                       break;
+                       return ret;
        }
 
-       return ret;
+       return False;
 }
 
 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL 
*uni,

Reply via email to