Adding test

/CoreOS/expat/Sanity/handlers
This commit is contained in:
František Hrdina 2023-03-16 12:14:39 +01:00
commit 3df8a592ec
15 changed files with 472 additions and 0 deletions

View file

@ -0,0 +1,40 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
void XML_startElement (void * userData,
const XML_Char * name, const XML_Char ** atts)
{
printf("Start....... %s\n", name ? name : "<null>");
}
void XML_endElement (void * userData,
const XML_Char * name)
{
printf("End......... %s\n", name ? name : "<null>");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetElementHandler(p, XML_startElement, XML_endElement);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,37 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
void XML_startCdata (void * userData)
{
}
void XML_endCdata (void * userData)
{
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetCdataSectionHandler(p, XML_startCdata, XML_endCdata);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetCharacterDataHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetCommentHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetDefaultHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetDefaultHandlerExpand(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetExternalEntityRefHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,39 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
void XML_startNamespaceDecl(void *userData,
const XML_Char *prefix,
const XML_Char *uri)
{
}
void XML_endNamespaceDecl (void * userData,
const XML_Char * prefix)
{
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetNamespaceDeclHandler(p, XML_startNamespaceDecl, XML_endNamespaceDecl);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetNotStandaloneHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetNotationDeclHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetProcessingInstructionHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,31 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void XML_unknownEncoding(void *encodingHandlerData,
const XML_Char *name,
XML_Encoding *info)
{
}
int main(int argc, char **argv)
{
void *encodingHandlerData;
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetUnknownEncodingHandler(p, XML_unknownEncoding, encodingHandlerData);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <expat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
static void default_handler(void *userData, const XML_Char *s, int len)
{
fprintf(stderr, "default_handler.\n");
}
int main(int argc, char **argv)
{
static const char pythontest1[] = { '\0', '\r', '\n' };
XML_Parser p;
p = XML_ParserCreate(NULL);
XML_SetUnparsedEntityDeclHandler(p, default_handler);
if (XML_Parse(p, pythontest1, 3, 1) == 0)
puts("parse fail");
XML_ParserFree(p);
return 0;
}

25
Sanity/handlers/main.fmf Normal file
View file

@ -0,0 +1,25 @@
summary: Test for C expat handlers
description: |4
Jan Lieskovsky <jlieskov@redhat.com>
C handlers test used for checking CVE-2009-3560. In the future we
could expand this for checking valid xml files as well.
http://www.xml.com/pub/a/1999/09/expat/index.html
contact: fhrdina@redhat.com
component:
- expat
test: ./runtest.sh
framework: beakerlib
recommend:
- expat
- expat-devel
- gcc
duration: 15m
enabled: true
tag:
- Tier1
tier: '1'
extra-nitrate: TC#0032973
extra-summary: /CoreOS/expat/Sanity/handlers
extra-task: /CoreOS/expat/Sanity/handlers

57
Sanity/handlers/runtest.sh Executable file
View file

@ -0,0 +1,57 @@
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/expat/Sanity/handlers
# Description: Test for C expat handlers
# Author: Petr Splichal <psplicha@redhat.com>
# Jan Lieskovsky <jlieskov@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2009 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="expat"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
rlRun "HandlersList=\`ls *.c | sed 's/\.c$//'\`" \
0 "Getting list of handlers"
rlRun "cp *.c $TmpDir" 0 "Copying source files"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
for handler in $HandlersList ; do
rlRun "gcc $handler.c -o $handler -l expat" 0 "Compiling $handler"
rlRun "./$handler" 0 "Testing $handler"
done
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd