Acked-by: Igor Mammedov <niallain@xxxxxxxxx> On Fri, Jan 7, 2011 at 5:11 PM, Jeff Layton <jlayton@xxxxxxxxx> wrote: > ...and switch the code to using strndup. Check for allocation errors as > well, and fix some off-by-one bugs in the ones that decode strings. > > Signed-off-by: Jeff Layton <jlayton@xxxxxxxxx> > --- > Âcifs.upcall.c |  30 ++++++++++++++++-------------- > Â1 files changed, 16 insertions(+), 14 deletions(-) > > diff --git a/cifs.upcall.c b/cifs.upcall.c > index 33b7e4c..d83dddf 100644 > --- a/cifs.upcall.c > +++ b/cifs.upcall.c > @@ -473,10 +473,13 @@ decode_key_description(const char *desc, struct decoded_args *arg) >            Âelse >                Âlen = pos - tkn; > > -            len -= 4; > +            len -= 5; >            ÂSAFE_FREE(arg->hostname); > -            arg->hostname = calloc(sizeof(char), len); > -            strlcpy(arg->hostname, tkn + 5, len); > +            arg->hostname = strndup(tkn + 5, len); > +            if (arg->hostname == NULL) { > +                syslog(LOG_ERR, "Unable to allocate memory"); > +                return 1; > +            } >            Âretval |= DKD_HAVE_HOSTNAME; >        Â} else if (!strncmp(tkn, "ip4=", 4) || !strncmp(tkn, "ip6=", 4)) { >            Âif (pos == NULL) > @@ -484,10 +487,13 @@ decode_key_description(const char *desc, struct decoded_args *arg) >            Âelse >                Âlen = pos - tkn; > > -            len -= 3; > +            len -= 4; >            ÂSAFE_FREE(arg->ip); > -            arg->ip = calloc(sizeof(char), len); > -            strlcpy(arg->ip, tkn + 4, len); > +            arg->ip = strndup(tkn + 4, len); > +            if (arg->ip == NULL) { > +                syslog(LOG_ERR, "Unable to allocate memory"); > +                return 1; > +            } >            Âretval |= DKD_HAVE_IP; >        Â} else if (strncmp(tkn, "pid=", 4) == 0) { >            Âerrno = 0; > @@ -496,9 +502,8 @@ decode_key_description(const char *desc, struct decoded_args *arg) >                Âsyslog(LOG_ERR, "Invalid pid format: %s", >                    strerror(errno)); >                Âreturn 1; > -            } else { > -                retval |= DKD_HAVE_PID; >            Â} > +            retval |= DKD_HAVE_PID; >        Â} else if (strncmp(tkn, "sec=", 4) == 0) { >            Âif (strncmp(tkn + 4, "krb5", 4) == 0) { >                Âretval |= DKD_HAVE_SEC; > @@ -514,9 +519,8 @@ decode_key_description(const char *desc, struct decoded_args *arg) >                Âsyslog(LOG_ERR, "Invalid uid format: %s", >                    strerror(errno)); >                Âreturn 1; > -            } else { > -                retval |= DKD_HAVE_UID; >            Â} > +            retval |= DKD_HAVE_UID; >        Â} else if (strncmp(tkn, "creduid=", 8) == 0) { >            Âerrno = 0; >            Âarg->creduid = strtol(tkn + 8, NULL, 16); > @@ -524,9 +528,8 @@ decode_key_description(const char *desc, struct decoded_args *arg) >                Âsyslog(LOG_ERR, "Invalid creduid format: %s", >                    strerror(errno)); >                Âreturn 1; > -            } else { > -                retval |= DKD_HAVE_CREDUID; >            Â} > +            retval |= DKD_HAVE_CREDUID; >        Â} else if (strncmp(tkn, "ver=", 4) == 0) {   Â/* if version */ >            Âerrno = 0; >            Âarg->ver = strtol(tkn + 4, NULL, 16); > @@ -534,9 +537,8 @@ decode_key_description(const char *desc, struct decoded_args *arg) >                Âsyslog(LOG_ERR, "Invalid version format: %s", >                    strerror(errno)); >                Âreturn 1; > -            } else { > -                retval |= DKD_HAVE_VERSION; >            Â} > +            retval |= DKD_HAVE_VERSION; >        Â} >        Âif (pos == NULL) >            Âbreak; > -- > 1.7.3.4 > > ÿô.nÇ·®+%˱é¥wÿº{.nÇ·¥{±ý¶¡Ü}©²ÆzÚj:+v¨þø®w¥þàÞ¨è&¢)ß«a¶Úÿûz¹ÞúÝjÿwèf