summaryrefslogtreecommitdiff
path: root/test/teststr.c
diff options
context:
space:
mode:
authorRyan Bloom <rbb@apache.org>2002-08-25 04:10:40 +0000
committerRyan Bloom <rbb@apache.org>2002-08-25 04:10:40 +0000
commit70bdb23bb288df73c7b97851cabcfba076141aab (patch)
treea19419ae31e0648ce4275db9acdd02a6e34dfc08 /test/teststr.c
parent8610f7e08f10b887544351f339ad480bad3ca2f6 (diff)
downloadapr-70bdb23bb288df73c7b97851cabcfba076141aab.tar.gz
Printing a string with apr_snprintf can seg fault, if a precision is
specified for the string, and the string being printed doesn't have a trailing '\0'. Fix that seg fault by not calling strlen if a precision is specified when printing a string. Also add a test to the test suite for this case. PR: 8554 Submitted by: R Samuel Klatchko <rsk@brightmail.com> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63828 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/teststr.c')
-rw-r--r--test/teststr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/teststr.c b/test/teststr.c
index 29279aa21..4a341d041 100644
--- a/test/teststr.c
+++ b/test/teststr.c
@@ -54,6 +54,7 @@
#include <assert.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include "apr_general.h"
@@ -119,6 +120,27 @@ static void test_strtok(apr_pool_t *p)
}
}
+void test_snprintf(apr_pool_t *p)
+{
+ char buff[100];
+ char *testing = apr_palloc(p, 10);
+
+ testing[0] = 't';
+ testing[1] = 'e';
+ testing[2] = 's';
+ testing[3] = 't';
+ testing[4] = 'i';
+ testing[5] = 'n';
+ testing[6] = 'g';
+
+ fprintf(stderr, "Testing precision ........ ");
+ apr_snprintf(buff, sizeof(buff), "%.*s", 7, testing);
+ if (!strncmp(buff, testing, 7)) {
+ fprintf(stderr, "OK\n");
+ }
+
+}
+
int main(int argc, const char * const argv[])
{
apr_pool_t *p;
@@ -128,6 +150,7 @@ int main(int argc, const char * const argv[])
apr_pool_create(&p, NULL);
test_strtok(p);
+ test_snprintf(p);
return 0;
}