File 0140-2169527-attrsOk_alloca_fix.patch of Package sblim-sfcb

Index: cimXmlParser.c
===================================================================
RCS file: /cvsroot/sblim/sfcb/cimXmlParser.c,v
retrieving revision 1.29
diff -u -p -r1.29 cimXmlParser.c
--- cimXmlParser.c	15 Aug 2008 19:05:13 -0000	1.29
+++ cimXmlParser.c	15 Oct 2008 21:16:29 -0000
@@ -42,7 +42,7 @@ typedef struct tags {
 } Tags;
 
 
-
+/* TODO: be more graceful than just exit()  */
 static void Throw(XmlBuffer * xb, char *msg)
 {
    printf("*** Error: %s\n", msg);
@@ -281,13 +281,15 @@ static int attrsOk(XmlBuffer * xb, const
       return 1;
    }
 
-   ptr = (char *) alloca(strlen(tag) + strlen(msg2) + 48);
+   /* build error message for Throw(): "Bad attribute list for: <TAG>: <chars...> */
+   ptr = (char*)alloca(strlen(msg2) + strlen(tag) + sizeof(char)*2 + strlen(word));
    strcpy(ptr, msg2);
    strcat(ptr, tag);
    strcat(ptr, ": ");
-   strncpy(word, xb->cur, 10);
-   strcat(ptr, word);
-   strcat(ptr, tag);
+   /* ensure we have at least 10 chars left in the XML */
+   int wlen = (xb->cur < (xb->last - 10)) ? 10 : (xb->last - xb->cur); 
+   strncpy(word, xb->cur, wlen);
+   strncat(ptr, word, wlen);
    Throw(xb, ptr);
    return -1;
 }

 	  	 
openSUSE Build Service is sponsored by