2014-08-18 9:23 GMT+04:00 Kent R. Spillner <[email protected]>:
> Haven't tested, just eyeballing the diff; I have two questions inline
> below.
> 1). Did you want to use proglen here?
Yep, good catch, thanks!
> 2). proglen is declared as an int; is there any danger malicious
> values could cause an overflow, or are all of those values carefully
> controlled?
Looking at the CVS code, it would blow up on overflowing int anyway,
so I don't care. Maybe I'm wrong...
Sending updated diff for archives; to be revisited when (if) more
complete commitid support will hit gnu/usr.bin/cvs itself.
--
WBR,
Vadim Zhukov
Index: src/logmsg.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/cvs/src/logmsg.c,v
retrieving revision 1.4
diff -u -p -r1.4 logmsg.c
--- src/logmsg.c 4 Mar 2012 04:05:15 -0000 1.4
+++ src/logmsg.c 19 Aug 2014 17:19:54 -0000
@@ -584,6 +584,9 @@ title_proc (p, closure)
{
switch (*c)
{
+ case 'i':
+ /* handled in caller */
+ continue;
case 's':
str_list =
xrealloc (str_list,
@@ -677,6 +680,7 @@ logfile_write (repository, filter, messa
or followed by a set of format characters surrounded by `{' and
`}' as separators. The format characters are:
+ i = commit ID
s = file name
t = tag name
V = old version number (pre-checkin)
@@ -685,6 +689,7 @@ logfile_write (repository, filter, messa
For example, valid format strings are:
%{}
+ %i
%s
%{s}
%{sVv}
@@ -709,10 +714,12 @@ logfile_write (repository, filter, messa
Why this duplicates the old behavior when the format string is
`%s' is left as an exercise for the reader. */
- fmt_percent = strchr (filter, '%');
+ fmt_percent = filter;
+find_percent:
+ fmt_percent = strchr (fmt_percent, '%');
if (fmt_percent)
{
- int len;
+ int len, proglen;
char *srepos;
char *fmt_begin, *fmt_end; /* beginning and end of the
format string specified in
@@ -737,6 +744,12 @@ logfile_write (repository, filter, messa
fmt_end = fmt_begin;
fmt_continue = fmt_begin;
}
+ else if (*(fmt_percent + 1) == '%')
+ {
+ memmove(fmt_percent, fmt_percent+1, strlen(fmt_percent));
+ fmt_percent++;
+ goto find_percent;
+ }
else if (*(fmt_percent + 1) == '{')
{
/* The percent has a set of characters following it. */
@@ -762,8 +775,7 @@ logfile_write (repository, filter, messa
}
else
{
- /* The percent has a single character following it. FIXME:
- %% should expand to a regular percent sign. */
+ /* The percent has a single character following it. */
fmt_begin = fmt_percent + 1;
fmt_end = fmt_begin + 1;
@@ -795,19 +807,26 @@ logfile_write (repository, filter, messa
type = T_REMOVED;
(void) walklist (changes, title_proc, NULL);
}
-
- free (str_list_format);
/* Construct the final string. */
srepos = Short_Repository (repository);
- prog = cp = xmalloc ((fmt_percent - filter) + 2 * strlen (srepos)
+ proglen = (fmt_percent - filter) + 2 * strlen (srepos)
+ 2 * strlen (str_list) + strlen (fmt_continue)
- + 10);
+ + 10;
+ if (strchr (str_list_format, 'i') != NULL)
+ /* assume no escaping needed */
+ proglen += strlen (global_session_id) * 2 + 1;
+
+ prog = cp = xmalloc (proglen);
(void) memcpy (cp, filter, fmt_percent - filter);
cp += fmt_percent - filter;
*cp++ = '"';
+ if (strchr (str_list_format, 'i') != NULL) {
+ cp = shell_escape (cp, global_session_id);
+ *cp++ = ' ';
+ }
cp = shell_escape (cp, srepos);
cp = shell_escape (cp, str_list);
*cp++ = '"';
@@ -815,6 +834,7 @@ logfile_write (repository, filter, messa
/* To be nice, free up some memory. */
+ free (str_list_format);
free (str_list);
str_list = (char *) NULL;
}
Index: src/mkmodules.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/cvs/src/mkmodules.c,v
retrieving revision 1.11
diff -u -p -r1.11 mkmodules.c
--- src/mkmodules.c 4 Mar 2012 04:05:15 -0000 1.11
+++ src/mkmodules.c 19 Aug 2014 17:19:54 -0000
@@ -65,6 +65,7 @@ static const char *const loginfo_content
"# characters surrounded by `{' and `}' as separators. The format\n",
"# characters are:\n",
"#\n",
+ "# i = commit ID\n",
"# s = file name\n",
"# t = tag name\n",
"# V = old version number (pre-checkin)\n",
@@ -73,7 +74,7 @@ static const char *const loginfo_content
"# For example:\n",
"#DEFAULT (echo \"\"; id; echo %s; date; cat) >>
$CVSROOT/CVSROOT/commitlog\n",
"# or\n",
- "#DEFAULT (echo \"\"; id; echo %{sVv}; date; cat) >>
$CVSROOT/CVSROOT/commitlog\n",
+ "#DEFAULT (echo \"\"; id; echo %{isVv}; date; cat) >>
$CVSROOT/CVSROOT/commitlog\n",
NULL
};