s3:smbcacls fix possible SEGFAULT
authorGregor Beck <gbeck@sernet.de>
Tue, 14 Jun 2011 11:56:22 +0000 (13:56 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 12 Oct 2011 01:49:05 +0000 (03:49 +0200)
sddl_encode returns NULL on failure

Signed-off-by: Michael Adam <obnox@samba.org>
source3/utils/smbcacls.c

index f6b2ba65aaacaa207495736030a7b397e036827a..bb7746e6b00bbf78c1d68453d88bc9608d9e943e 100644 (file)
@@ -894,25 +894,29 @@ dump the acls for a file
 *******************************************************/
 static int cacl_dump(struct cli_state *cli, const char *filename)
 {
-       int result = EXIT_FAILED;
        struct security_descriptor *sd;
 
-       if (test_args)
+       if (test_args) {
                return EXIT_OK;
+       }
 
        sd = get_secdesc(cli, filename);
+       if (sd == NULL) {
+               return EXIT_FAILED;
+       }
 
-       if (sd) {
-               if (sddl) {
-                       printf("%s\n", sddl_encode(talloc_tos(), sd,
-                                          get_domain_sid(cli)));
-               } else {
-                       sec_desc_print(cli, stdout, sd);
+       if (sddl) {
+               char *str = sddl_encode(talloc_tos(), sd, get_domain_sid(cli));
+               if (str == NULL) {
+                       return EXIT_FAILED;
                }
-               result = EXIT_OK;
+               printf("%s\n", str);
+               TALLOC_FREE(str);
+       } else {
+               sec_desc_print(cli, stdout, sd);
        }
 
-       return result;
+       return EXIT_OK;
 }
 
 /*****************************************************