Re: [Patch 1/3] tabled: make time2str reentrant

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>

---
  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@xxxxxxxxxxxxxxxxxxxxx>
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



--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Fedora Clound]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux