{"thread":{"id":"21086","subject":"[PATCH 1/2] builtin-mailinfo.c: check error status from rewind and ftruncate","startedAt":"2009-09-29T06:40:08Z","lastAt":"2009-09-29T16:40:46Z","messageCount":3,"participants":["Junio C Hamano","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"123973","messageId":"1254206409-13256-1-git-send-email-gitster@pobox.com","threadId":"21086","inReplyTo":null,"subject":"[PATCH 1/2] builtin-mailinfo.c: check error status from rewind and ftruncate","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-09-29T06:40:08Z","receivedAt":"2009-09-29T06:40:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"A recent \"cut at scissors\" implementation rewinds and truncates the output\nfile to store the message when it sees a scissors mark, but it did not\ncheck if these library calls succeeded.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-mailinfo.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex d498b1c..3306d9e 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -785,8 +785,10 @@ static int handle_commit_msg(struct strbuf *line)\n \n \tif (use_scissors && is_scissors_line(line)) {\n \t\tint i;\n-\t\trewind(cmitmsg);\n-\t\tftruncate(fileno(cmitmsg), 0);\n+\t\tif (rewind(cmitmsg))\n+\t\t\tdie_errno(\"Could not rewind output message file\");\n+\t\tif (ftruncate(fileno(cmitmsg), 0))\n+\t\t\tdie_errno(\"Could not truncate output message file at scissors\");\n \t\tstill_looking = 1;\n \n \t\t/*\n-- \n1.6.3\n"},{"id":"123974","messageId":"1254206409-13256-2-git-send-email-gitster@pobox.com","threadId":"21086","inReplyTo":"1254206409-13256-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/2] fast-import.c::validate_raw_date(): really validate the value","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-09-29T06:40:09Z","receivedAt":"2009-09-29T06:40:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When reading the \"raw format\" timestamp from the input stream, make sure\nthat the timezone offset is a reasonable value by imitating 7122f82\n(date.c: improve guess between timezone offset and year., 2006-06-08).\n\nWe _might_ want to also check if the timestamp itself is reasonable, but\nthat is left for a separate commit.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n fast-import.c |    9 ++++++---\n 1 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 7ef9865..6faaaac 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1744,10 +1744,12 @@ static int validate_raw_date(const char *src, char *result, int maxlen)\n {\n \tconst char *orig_src = src;\n \tchar *endp;\n+\tunsigned long num;\n \n \terrno = 0;\n \n-\tstrtoul(src, &endp, 10);\n+\tnum = strtoul(src, &endp, 10);\n+\t/* NEEDSWORK: perhaps check for reasonable values? */\n \tif (errno || endp == src || *endp != ' ')\n \t\treturn -1;\n \n@@ -1755,8 +1757,9 @@ static int validate_raw_date(const char *src, char *result, int maxlen)\n \tif (*src != '-' && *src != '+')\n \t\treturn -1;\n \n-\tstrtoul(src + 1, &endp, 10);\n-\tif (errno || endp == src || *endp || (endp - orig_src) >= maxlen)\n+\tnum = strtoul(src + 1, &endp, 10);\n+\tif (errno || endp == src + 1 || *endp || (endp - orig_src) >= maxlen ||\n+\t    1400 < num)\n \t\treturn -1;\n \n \tstrcpy(result, orig_src);\n-- \n1.6.3\n"},{"id":"124002","messageId":"20090929164046.GB25756@spearce.org","threadId":"21086","inReplyTo":"1254206409-13256-1-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 1/2] builtin-mailinfo.c: check error status from rewind and ftruncate","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-09-29T16:40:46Z","receivedAt":"2009-09-29T16:40:46Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> A recent \"cut at scissors\" implementation rewinds and truncates the output\n> file to store the message when it sees a scissors mark, but it did not\n> check if these library calls succeeded.\n...\n> diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\n> index d498b1c..3306d9e 100644\n> --- a/builtin-mailinfo.c\n> +++ b/builtin-mailinfo.c\n> @@ -785,8 +785,10 @@ static int handle_commit_msg(struct strbuf *line)\n>  \n>  \tif (use_scissors && is_scissors_line(line)) {\n>  \t\tint i;\n> -\t\trewind(cmitmsg);\n> -\t\tftruncate(fileno(cmitmsg), 0);\n> +\t\tif (rewind(cmitmsg))\n\nUh...\n\nbuiltin-mailinfo.c: In function 'handle_commit_msg':\nbuiltin-mailinfo.c:788: error: void value not ignored as it ought to be\n\nI think you mean to squash this in, and use fseek instead:\n\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex 3306d9e..c90cd31 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -785,7 +785,7 @@ static int handle_commit_msg(struct strbuf *line)\n \n \tif (use_scissors && is_scissors_line(line)) {\n \t\tint i;\n-\t\tif (rewind(cmitmsg))\n+\t\tif (fseek(cmitmsg, 0L, SEEK_SET))\n \t\t\tdie_errno(\"Could not rewind output message file\");\n \t\tif (ftruncate(fileno(cmitmsg), 0))\n \t\t\tdie_errno(\"Could not truncate output message file at scissors\");\n\n-- \nShawn.\n"}]}