two fixes: buffer overrun and strncpy overlap [Re: texinfo 4.6.92 ...

Jim Meyering <[email protected]> Fri, 19 Mar 2004 11:38:31 +0100
Newsgroups gmane.comp.tex.texinfo.pretest
Message-ID <[email protected]>
Hi Karl,

Here are fixes for the two other problems I mentioned on Sunday.

2004-03-19  Jim Meyering  <[email protected]>

	* makeinfo/makeinfo.c (add_char): Use memmove, rather than strncpy,
	since source and destination strings overlap.

	* makeinfo/float.c (add_new_float): Avoid buffer overrun when
	appending `.' to a chapter number.

Index: makeinfo/makeinfo.c
===================================================================
--- makeinfo/makeinfo.c	(revision 6)
+++ makeinfo/makeinfo.c	(working copy)
@@ -2688,9 +2688,9 @@
                           if (t1 != temp)
                             {
                               adjust_braces_following (temp, (- (t1 - temp)));
-                              strncpy ((char *) &output_paragraph[temp],
-                                       (char *) &output_paragraph[t1],
-                                       (output_paragraph_offset - t1));
+                              memmove (&output_paragraph[temp],
+                                       &output_paragraph[t1],
+                                       output_paragraph_offset - t1);
                               output_paragraph_offset -= (t1 - temp);
                             }
                         }
Index: makeinfo/float.c
===================================================================
--- makeinfo/float.c	(revision 6)
+++ makeinfo/float.c	(working copy)
@@ -35,6 +35,7 @@
     char *type, char *position)
 {
   FLOAT_ELT *new = xmalloc (sizeof (FLOAT_ELT));
+  size_t num_len;
 
   new->id = id;
   new->type = type;
@@ -46,8 +47,13 @@
 
   new->number = current_chapter_number ();
   /* Append dot if not @unnumbered.  */
-  if (strlen (new->number) > 0)
-    strcat (new->number, ".");
+  num_len = strlen (new->number);
+  if (num_len > 0)
+    {
+      new->number = xrealloc (new->number, num_len + 1 + 1);
+      new->number[num_len] = '.';
+      new->number[num_len+1] = '\0';
+    }
 
   { /* Append the current float number.  */
     char s[100];
_______________________________________________
Texinfo home page: http://www.gnu.org/software/texinfo/
[email protected]
http://ff0.org/mailman/listinfo/texinfo-pretest