Fossil SCM

fixed a potential crash in /json/wiki/get when page contents are NULL.

stephan 2012-02-17 12:43 trunk
Commit fca6c46cd99534fb7ec81340840b96c5e2369601
1 file changed +15 -12
+15 -12
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -64,12 +64,10 @@
6464
** caller. If it returns NULL then it may set g.json's error state.
6565
*/
6666
cson_value * json_get_wiki_page_by_name(char const * zPageName, char contentFormat){
6767
int rid;
6868
Manifest *pWiki = 0;
69
- char const * zBody = NULL;
70
- char const * zFormat = NULL;
7169
char * zUuid = NULL;
7270
Stmt q;
7371
db_prepare(&q,
7472
"SELECT x.rid, b.uuid FROM tag t, tagxref x, blob b"
7573
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
@@ -84,17 +82,21 @@
8482
return NULL;
8583
}
8684
rid = db_column_int(&q,0);
8785
zUuid = db_column_malloc(&q,1);
8886
db_finalize(&q);
89
- if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
90
- zBody = pWiki->zWiki;
91
- }
92
-
93
- {
94
- unsigned int len;
87
+ if( NULL == (pWiki = manifest_get(rid, CFTYPE_WIKI)) ){
88
+ free(zUuid);
89
+ json_set_err( FSL_JSON_E_UNKNOWN,
90
+ "Error reading wiki page from manifest (rid=%d, uuid=%s).",
91
+ rid, zUuid );
92
+ return NULL;
93
+ }else{
94
+ char const * zFormat = NULL;
95
+ unsigned int len = 0;
9596
cson_object * pay = cson_new_object();
97
+ char const * zBody = pWiki->zWiki;
9698
cson_object_set(pay,"name",json_new_string(zPageName));
9799
cson_object_set(pay,"uuid",json_new_string(zUuid));
98100
free(zUuid);
99101
zUuid = NULL;
100102
/*cson_object_set(pay,"rid",json_new_int((cson_int_t)rid));*/
@@ -109,14 +111,15 @@
109111
}else{
110112
cson_object_set(pay,"contentFormat",json_new_string(zFormat));
111113
if( contentFormat>0 ){/*HTML-ize it*/
112114
Blob content = empty_blob;
113115
Blob raw = empty_blob;
114
- blob_append(&raw,zBody,-1);
115
- wiki_convert(&raw,&content,0);
116
- len = strlen(zBody);
117
- len = (unsigned int)blob_size(&content);
116
+ if(zBody && *zBody){
117
+ blob_append(&raw,zBody,-1);
118
+ wiki_convert(&raw,&content,0);
119
+ len = (unsigned int)blob_size(&content);
120
+ }
118121
cson_object_set(pay,"contentLength",json_new_int((cson_int_t)len));
119122
cson_object_set(pay,"content",
120123
cson_value_new_string(blob_buffer(&content),len));
121124
blob_reset(&content);
122125
blob_reset(&raw);
123126
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -64,12 +64,10 @@
64 ** caller. If it returns NULL then it may set g.json's error state.
65 */
66 cson_value * json_get_wiki_page_by_name(char const * zPageName, char contentFormat){
67 int rid;
68 Manifest *pWiki = 0;
69 char const * zBody = NULL;
70 char const * zFormat = NULL;
71 char * zUuid = NULL;
72 Stmt q;
73 db_prepare(&q,
74 "SELECT x.rid, b.uuid FROM tag t, tagxref x, blob b"
75 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
@@ -84,17 +82,21 @@
84 return NULL;
85 }
86 rid = db_column_int(&q,0);
87 zUuid = db_column_malloc(&q,1);
88 db_finalize(&q);
89 if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
90 zBody = pWiki->zWiki;
91 }
92
93 {
94 unsigned int len;
 
 
 
95 cson_object * pay = cson_new_object();
 
96 cson_object_set(pay,"name",json_new_string(zPageName));
97 cson_object_set(pay,"uuid",json_new_string(zUuid));
98 free(zUuid);
99 zUuid = NULL;
100 /*cson_object_set(pay,"rid",json_new_int((cson_int_t)rid));*/
@@ -109,14 +111,15 @@
109 }else{
110 cson_object_set(pay,"contentFormat",json_new_string(zFormat));
111 if( contentFormat>0 ){/*HTML-ize it*/
112 Blob content = empty_blob;
113 Blob raw = empty_blob;
114 blob_append(&raw,zBody,-1);
115 wiki_convert(&raw,&content,0);
116 len = strlen(zBody);
117 len = (unsigned int)blob_size(&content);
 
118 cson_object_set(pay,"contentLength",json_new_int((cson_int_t)len));
119 cson_object_set(pay,"content",
120 cson_value_new_string(blob_buffer(&content),len));
121 blob_reset(&content);
122 blob_reset(&raw);
123
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -64,12 +64,10 @@
64 ** caller. If it returns NULL then it may set g.json's error state.
65 */
66 cson_value * json_get_wiki_page_by_name(char const * zPageName, char contentFormat){
67 int rid;
68 Manifest *pWiki = 0;
 
 
69 char * zUuid = NULL;
70 Stmt q;
71 db_prepare(&q,
72 "SELECT x.rid, b.uuid FROM tag t, tagxref x, blob b"
73 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
@@ -84,17 +82,21 @@
82 return NULL;
83 }
84 rid = db_column_int(&q,0);
85 zUuid = db_column_malloc(&q,1);
86 db_finalize(&q);
87 if( NULL == (pWiki = manifest_get(rid, CFTYPE_WIKI)) ){
88 free(zUuid);
89 json_set_err( FSL_JSON_E_UNKNOWN,
90 "Error reading wiki page from manifest (rid=%d, uuid=%s).",
91 rid, zUuid );
92 return NULL;
93 }else{
94 char const * zFormat = NULL;
95 unsigned int len = 0;
96 cson_object * pay = cson_new_object();
97 char const * zBody = pWiki->zWiki;
98 cson_object_set(pay,"name",json_new_string(zPageName));
99 cson_object_set(pay,"uuid",json_new_string(zUuid));
100 free(zUuid);
101 zUuid = NULL;
102 /*cson_object_set(pay,"rid",json_new_int((cson_int_t)rid));*/
@@ -109,14 +111,15 @@
111 }else{
112 cson_object_set(pay,"contentFormat",json_new_string(zFormat));
113 if( contentFormat>0 ){/*HTML-ize it*/
114 Blob content = empty_blob;
115 Blob raw = empty_blob;
116 if(zBody && *zBody){
117 blob_append(&raw,zBody,-1);
118 wiki_convert(&raw,&content,0);
119 len = (unsigned int)blob_size(&content);
120 }
121 cson_object_set(pay,"contentLength",json_new_int((cson_int_t)len));
122 cson_object_set(pay,"content",
123 cson_value_new_string(blob_buffer(&content),len));
124 blob_reset(&content);
125 blob_reset(&raw);
126

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button