good for commit regards -steve
On Fri, 2009-03-20 at 11:07 +0100, Jim Meyering wrote: > Steven Dake wrote: > > I merged this patch but it had rejects and I attempted to fix them but > > it broke corosync so I reverted the patch. > > > > Could you work up a new version? > > Sure. > > FYI, removing the use of strtok from within the loop > is what broke corosync. > > Ok to commit these? > The first is new. > The other two are essentially identical to what I posted yesterday, > but with added curly braces around one-line if-blocks. > > From b583ffaba3c236bad39381a39db0a8042dac135c Mon Sep 17 00:00:00 2001 > From: Jim Meyering <[email protected]> > Date: Fri, 20 Mar 2009 08:44:59 +0100 > Subject: [PATCH 1/3] don't segfault upon failed strdup > > * sa-confdb.c (load_config): Handle out-of-memory. > --- > lib/sa-confdb.c | 8 ++++++-- > 1 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/lib/sa-confdb.c b/lib/sa-confdb.c > index 8871cdd..709179a 100644 > --- a/lib/sa-confdb.c > +++ b/lib/sa-confdb.c > @@ -103,11 +103,15 @@ static int load_config(void) > /* User's bootstrap config service */ > config_iface = getenv("COROSYNC_DEFAULT_CONFIG_IFACE"); > if (!config_iface) { > - config_iface = strdup("corosync_parser"); > + if ((config_iface = strdup("corosync_parser")) == NULL) { > + return -1; > + } > } > > /* Make a copy so we can deface it with strtok */ > - config_iface = strdup(config_iface); > + if ((config_iface = strdup(config_iface)) == NULL) { > + return -1; > + } > > iface = strtok(config_iface, ":"); > while (iface) > -- > 1.6.2.rc1.285.gc5f54 > > > From 8de1640b30fde6ba56f76e24a94267c3a6af25c7 Mon Sep 17 00:00:00 2001 > From: Jim Meyering <[email protected]> > Date: Fri, 20 Mar 2009 09:21:39 +0100 > Subject: [PATCH 2/3] don't store (and later deref) NULL upon strdup failure > > * lcr_ifact.c (ld_library_path_build, ldso_path_build): > Handle strdup failure. > --- > lcr/lcr_ifact.c | 11 +++++++++-- > 1 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/lcr/lcr_ifact.c b/lcr/lcr_ifact.c > index b1ea5dc..caaa280 100644 > --- a/lcr/lcr_ifact.c > +++ b/lcr/lcr_ifact.c > @@ -200,7 +200,10 @@ static void ld_library_path_build (void) > > p_s = strtok_r (my_ld_library_path, ":", &ptrptr); > while (p_s != NULL) { > - path_list[path_list_entries++] = strdup (p_s); > + char *p = strdup (p_s); > + if (p) { > + path_list[path_list_entries++] = p; > + } > p_s = strtok_r (NULL, ":", &ptrptr); > } > > @@ -243,6 +246,7 @@ static int ldso_path_build (const char *path, const char > *filename) > } > > while (fgets (string, sizeof (string), fp)) { > + char *p; > if (strlen(string) > 0) > string[strlen(string) - 1] = '\0'; > if (strncmp (string, "include", strlen ("include")) == 0) { > @@ -261,7 +265,10 @@ static int ldso_path_build (const char *path, const char > *filename) > ldso_path_build (newpath, new_filename); > continue; > } > - path_list[path_list_entries++] = strdup (string); > + p = strdup (string); > + if (p) { > + path_list[path_list_entries++] = p; > + } > } > fclose(fp); > #endif > -- > 1.6.2.rc1.285.gc5f54 > > > From 784b96488c26d0ddd20a817f51afcfb2196d3e2e Mon Sep 17 00:00:00 2001 > From: Jim Meyering <[email protected]> > Date: Fri, 20 Mar 2009 09:35:02 +0100 > Subject: [PATCH 3/3] avoid buffer overrun when there are more than 128 path > entries > > * lcr_ifact.c (PATH_LIST_SIZE): Define. > (path_list): Use it. > (ld_library_path_build): Don't store into path_list[path_list_entries] > if the counter is too large. > (ldso_path_build): Likewise. > --- > lcr/lcr_ifact.c | 7 ++++--- > 1 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/lcr/lcr_ifact.c b/lcr/lcr_ifact.c > index caaa280..c447a67 100644 > --- a/lcr/lcr_ifact.c > +++ b/lcr/lcr_ifact.c > @@ -167,7 +167,8 @@ static inline int lcr_lib_loaded ( > return (0); > } > > -const char *path_list[128]; > +enum { PATH_LIST_SIZE = 128 }; > +const char *path_list[PATH_LIST_SIZE]; > unsigned int path_list_entries = 0; > > static void defaults_path_build (void) > @@ -201,7 +202,7 @@ static void ld_library_path_build (void) > p_s = strtok_r (my_ld_library_path, ":", &ptrptr); > while (p_s != NULL) { > char *p = strdup (p_s); > - if (p) { > + if (p && path_list_entries < PATH_LIST_SIZE) { > path_list[path_list_entries++] = p; > } > p_s = strtok_r (NULL, ":", &ptrptr); > @@ -266,7 +267,7 @@ static int ldso_path_build (const char *path, const char > *filename) > continue; > } > p = strdup (string); > - if (p) { > + if (p && path_list_entries < PATH_LIST_SIZE) { > path_list[path_list_entries++] = p; > } > } > -- > 1.6.2.rc1.285.gc5f54 _______________________________________________ Openais mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/openais
