From: Jeff Garzik <jeff@garzik.org>
To: Pete Zaitcev <zaitcev@redhat.com>
Cc: Project Hail List <hail-devel@vger.kernel.org>
Subject: Re: [Patch 1/3] tabled: make time2str reentrant
Date: Sun, 03 Jan 2010 03:27:59 -0500 [thread overview]
Message-ID: <4B40550F.5010907@garzik.org> (raw)
In-Reply-To: <20100103005630.369b3c77@redhat.com>
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<zaitcev@redhat.com>
>
> ---
> 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<zaitcev@niphredil.zaitcev.lan>
> 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
next prev parent reply other threads:[~2010-01-03 8:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-03 7:56 [Patch 1/3] tabled: make time2str reentrant Pete Zaitcev
2010-01-03 8:27 ` Jeff Garzik [this message]
2010-01-03 8:34 ` Pete Zaitcev
2010-01-03 21:27 ` Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B40550F.5010907@garzik.org \
--to=jeff@garzik.org \
--cc=hail-devel@vger.kernel.org \
--cc=zaitcev@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.