From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Garzik Subject: Re: [Patch 1/3] tabled: make time2str reentrant Date: Sun, 03 Jan 2010 03:27:59 -0500 Message-ID: <4B40550F.5010907@garzik.org> References: <20100103005630.369b3c77@redhat.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=LdvUVs5g3SW/m0imqHKaqnCQnNExC9E1rRyY0uROxgg=; b=A6YQO39sXXiaONBI2zkWbzVNTrX6pRZerD/Z7T7ao8JoXWy/PRWQU4f0lT+U2pMjUQ cfQ9XEAUDFZ6FLIkrfdbYL3qMiZzhgPJ3qhUhZArSQMIqtfALqNu47PvJiB0mwPZ7J3l 880l8B9yfPjPielErXTvWrtXu3WLEO3mIcjc8= In-Reply-To: <20100103005630.369b3c77@redhat.com> Sender: hail-devel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: Pete Zaitcev Cc: Project Hail List On 01/03/2010 02:56 AM, Pete Zaitcev wrote: > The main point here is to kill gmtime, but since we're at it, may as well > fix the API and add safety (observe, that not all timestr arguments were > 64 bytes long in the original code). > > Signed-Off-By: Pete Zaitcev > > --- > include/httputil.h | 2 +- > lib/httpstor.c | 12 ++++++------ > lib/httputil.c | 15 ++++++++++++--- > server/bucket.c | 8 ++++---- > server/object.c | 11 ++++++----- > server/server.c | 14 ++++++++------ > server/tabled.h | 1 - > 7 files changed, 37 insertions(+), 26 deletions(-) > > commit d180799fbd1eedc32eabc4e2335950714bd26b65 > Author: Master > Date: Sat Jan 2 23:36:11 2010 -0700 > > Fix time2str to be reentrant and safer. > > diff --git a/include/httputil.h b/include/httputil.h > index 7a1f6da..b2e8f30 100644 > --- a/include/httputil.h > +++ b/include/httputil.h > @@ -85,7 +85,7 @@ enum ReqACLC { > }; > > /* httputil.c */ > -extern char *time2str(char *strbuf, time_t time); > +extern char *time2str(char *buf, int len, time_t time); > extern time_t str2time(const char *timestr); > extern int req_hdr_push(struct http_req *req, char *key, char *val); > extern char *req_hdr(struct http_req *req, const char *key); > diff --git a/lib/httpstor.c b/lib/httpstor.c > index f69a317..a502858 100644 > --- a/lib/httpstor.c > +++ b/lib/httpstor.c > @@ -196,7 +196,7 @@ struct httpstor_blist *httpstor_list_buckets(struct httpstor_client *httpstor) > req.method = "GET"; > req.orig_path = "/"; > > - sprintf(datestr, "Date: %s", time2str(timestr, time(NULL))); > + sprintf(datestr, "Date: %s", time2str(timestr, 64, time(NULL))); > > req_hdr_push(&req, "Date", timestr); > > @@ -315,7 +315,7 @@ static bool __httpstor_ad_bucket(struct httpstor_client *httpstor, const char *n > req.method = delete ? "DELETE" : "PUT"; > req.orig_path = orig_path; > > - sprintf(datestr, "Date: %s", time2str(timestr, time(NULL))); > + sprintf(datestr, "Date: %s", time2str(timestr, 64, time(NULL))); > > req_hdr_push(&req, "Date", timestr); > > @@ -374,7 +374,7 @@ bool httpstor_get(struct httpstor_client *httpstor, const char *bucket, const ch > req.method = "GET"; > req.orig_path = orig_path; > > - sprintf(datestr, "Date: %s", time2str(timestr, time(NULL))); > + sprintf(datestr, "Date: %s", time2str(timestr, 64, time(NULL))); > > req_hdr_push(&req, "Date", timestr); > > @@ -453,7 +453,7 @@ bool httpstor_put(struct httpstor_client *httpstor, const char *bucket, const ch > req.method = "PUT"; > req.orig_path = orig_path; > > - sprintf(datestr, "Date: %s", time2str(timestr, time(NULL))); > + sprintf(datestr, "Date: %s", time2str(timestr, 64, time(NULL))); > > req_hdr_push(&req, "Date", timestr); > > @@ -544,7 +544,7 @@ bool httpstor_del(struct httpstor_client *httpstor, const char *bucket, const ch > req.method = "DELETE"; > req.orig_path = orig_path; > > - sprintf(datestr, "Date: %s", time2str(timestr, time(NULL))); > + sprintf(datestr, "Date: %s", time2str(timestr, 64, time(NULL))); > > req_hdr_push(&req, "Date", timestr); > > @@ -740,7 +740,7 @@ struct httpstor_keylist *httpstor_keys(struct httpstor_client *httpstor, const c > req.method = "GET"; > req.orig_path = orig_path; > > - sprintf(datestr, "Date: %s", time2str(timestr, time(NULL))); > + sprintf(datestr, "Date: %s", time2str(timestr, 64, time(NULL))); applied 1-3, and then added sizeof() to the above time2str calls... The hardcoded sizes I used for the strings is ugly enough... let's not add additional "naked numbers" on top of that. Jeff