[SCM] Samba Shared Repository - branch master updated

Michael Adam obnox at samba.org
Fri Mar 13 12:15:03 MDT 2015


The branch, master has been updated
       via  d171d20 ctdb: Fix CID 1125613 Destination buffer too small
       via  8d9bb5c ctdb: Introduce a helper var in ctdb_get_script_list
       via  c1e8bfb ctdb: Fix memleak in ctdb_get_script_list
       via  a8cc495 ctdb: Make for-loop in ctdb_get_script_list more idiomatic
       via  b584bde ctdb: Fix whitespace
      from  07330d2 replace: Remove superfluous check for gcrypt header.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d171d2010a256a46446de5328a0897df3838855a
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 13 14:20:05 2015 +0000

    ctdb: Fix CID 1125613 Destination buffer too small
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>
    
    Autobuild-User(master): Michael Adam <obnox at samba.org>
    Autobuild-Date(master): Fri Mar 13 19:14:20 CET 2015 on sn-devel-104

commit 8d9bb5c54aae0099e0dde2d9a904676fcb9340c0
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 13 14:16:17 2015 +0000

    ctdb: Introduce a helper var in ctdb_get_script_list
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit c1e8bfb186c5cbeafbce9f2767db82edb579d5e1
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 13 14:12:41 2015 +0000

    ctdb: Fix memleak in ctdb_get_script_list
    
    scandir allocates every name individually, see example code in susv4 or man
    scandir
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit a8cc495b967935852c5357c3a4ef3d37579fb51b
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 13 14:11:20 2015 +0000

    ctdb: Make for-loop in ctdb_get_script_list more idiomatic
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit b584bdebf9fc83f0b0c69d1dae7c582e8e8d2781
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 13 14:01:25 2015 +0000

    ctdb: Fix whitespace
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/server/eventscript.c | 63 ++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 26 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c
index e70db79..4dd4379 100644
--- a/ctdb/server/eventscript.c
+++ b/ctdb/server/eventscript.c
@@ -1,4 +1,4 @@
-/* 
+/*
    event script handling
 
    Copyright (C) Andrew Tridgell  2007
@@ -7,12 +7,12 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
@@ -38,7 +38,6 @@ struct event_script_callback {
 	void (*fn)(struct ctdb_context *, int, void *);
 	void *private_data;
 };
-	
 
 struct ctdb_event_script_state {
 	struct ctdb_context *ctdb;
@@ -48,7 +47,7 @@ struct ctdb_event_script_state {
 	enum ctdb_eventscript_call call;
 	const char *options;
 	struct timeval timeout;
-	
+
 	unsigned int current;
 	struct ctdb_scripts_wire *scripts;
 };
@@ -160,9 +159,9 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
 {
 	struct dirent **namelist;
 	struct ctdb_scripts_wire *scripts;
-	int count;
+	int i, count;
 
-	/* scan all directory entries and insert all valid scripts into the 
+	/* scan all directory entries and insert all valid scripts into the
 	   tree
 	*/
 	count = scandir(ctdb->event_script_dir, &namelist, script_filter, alphasort);
@@ -178,19 +177,30 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
 				   + sizeof(scripts->scripts[0]) * count);
 	if (scripts == NULL) {
 		DEBUG(DEBUG_ERR, (__location__ " Failed to allocate scripts\n"));
-		free(namelist);
-		return NULL;
+		goto done;
 	}
 	scripts->num_scripts = count;
 
-	for (count = 0; count < scripts->num_scripts; count++) {
-		strcpy(scripts->scripts[count].name, namelist[count]->d_name);
-		scripts->scripts[count].status = 0;
-		if (!check_executable(ctdb->event_script_dir, namelist[count]->d_name)) {
-			scripts->scripts[count].status = -errno;
+	for (i = 0; i < count; i++) {
+		struct ctdb_script_wire *s = &scripts->scripts[i];
+
+		if (strlcpy(s->name, namelist[i]->d_name, sizeof(s->name)) >=
+		    sizeof(s->name)) {
+			s->status = -ENAMETOOLONG;
+			continue;
+		}
+
+		s->status = 0;
+		if (!check_executable(ctdb->event_script_dir,
+				      namelist[i]->d_name)) {
+			s->status = -errno;
 		}
 	}
 
+done:
+	for (i=0; i<count; i++) {
+		free(namelist[i]);
+	}
 	free(namelist);
 	return scripts;
 }
@@ -330,6 +340,7 @@ static int script_status(struct ctdb_scripts_wire *scripts)
 
 	for (i = 0; i < scripts->num_scripts; i++) {
 		switch (scripts->scripts[i].status) {
+		case -ENAMETOOLONG:
 		case -ENOENT:
 		case -ENOEXEC:
 			/* Disabled or missing; that's OK. */
@@ -347,10 +358,10 @@ static int script_status(struct ctdb_scripts_wire *scripts)
 }
 
 /* called when child is finished */
-static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde, 
+static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde,
 				      uint16_t flags, void *p)
 {
-	struct ctdb_event_script_state *state = 
+	struct ctdb_event_script_state *state =
 		talloc_get_type(p, struct ctdb_event_script_state);
 	struct ctdb_script_wire *current = get_current_script(state);
 	struct ctdb_context *ctdb = state->ctdb;
@@ -508,7 +519,7 @@ static void ctdb_run_debug_hung_script(struct ctdb_context *ctdb, struct debug_h
 }
 
 /* called when child times out */
-static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, 
+static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te,
 				      struct timeval t, void *p)
 {
 	struct ctdb_event_script_state *state = talloc_get_type(p, struct ctdb_event_script_state);
@@ -610,7 +621,7 @@ static int event_script_destructor(struct ctdb_event_script_state *state)
 			break;
 		}
 	}
-	
+
 	state->callback = NULL;
 
 	if (callback) {
@@ -670,7 +681,7 @@ static int remove_callback(struct event_script_callback *callback)
 }
 
 /*
-  run the event script in the background, calling the callback when 
+  run the event script in the background, calling the callback when
   finished
  */
 static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
@@ -807,10 +818,10 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
 
 
 /*
-  run the event script in the background, calling the callback when 
+  run the event script in the background, calling the callback when
   finished.  If mem_ctx is freed, callback will never be called.
  */
-int ctdb_event_script_callback(struct ctdb_context *ctdb, 
+int ctdb_event_script_callback(struct ctdb_context *ctdb,
 			       TALLOC_CTX *mem_ctx,
 			       void (*callback)(struct ctdb_context *, int, void *),
 			       void *private_data,
@@ -895,10 +906,10 @@ struct eventscript_callback_state {
 /*
   called when a forced eventscript run has finished
  */
-static void run_eventscripts_callback(struct ctdb_context *ctdb, int status, 
+static void run_eventscripts_callback(struct ctdb_context *ctdb, int status,
 				 void *private_data)
 {
-	struct eventscript_callback_state *state = 
+	struct eventscript_callback_state *state =
 		talloc_get_type(private_data, struct eventscript_callback_state);
 
 	if (status != 0) {
@@ -964,7 +975,7 @@ int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
 
 	DEBUG(DEBUG_NOTICE,("Running eventscripts with arguments %s\n", indata.dptr));
 
-	ret = ctdb_event_script_callback(ctdb, 
+	ret = ctdb_event_script_callback(ctdb,
 			 state, run_eventscripts_callback, state,
 			 call, "%s", options);
 
@@ -1007,7 +1018,7 @@ int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata)
 	}
 
 
-	if (stat(ctdb->event_script_dir, &st) != 0 && 
+	if (stat(ctdb->event_script_dir, &st) != 0 &&
 	    errno == ENOENT) {
 		DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
 		talloc_free(tmp_ctx);
@@ -1063,7 +1074,7 @@ int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata)
 	}
 
 
-	if (stat(ctdb->event_script_dir, &st) != 0 && 
+	if (stat(ctdb->event_script_dir, &st) != 0 &&
 	    errno == ENOENT) {
 		DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
 		talloc_free(tmp_ctx);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list