use switch_snprintf instead of snprintf becuase in insures null termination of strings.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6707 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris
2007-12-12 21:53:32 +00:00
parent 44636d333f
commit 54ec86f6ce
49 changed files with 306 additions and 306 deletions

View File

@@ -880,13 +880,13 @@ static switch_status_t sm_load_module(const char *dir, const char *fname)
len += strlen(file);
len += 4;
path = (char *) switch_core_alloc(module_manager.pool, len);
snprintf(path, len, "%s%s%s", dir, SWITCH_PATH_SEPARATOR, file);
switch_snprintf(path, len, "%s%s%s", dir, SWITCH_PATH_SEPARATOR, file);
} else {
len = strlen(dir);
len += strlen(file);
len += 8;
path = (char *) switch_core_alloc(module_manager.pool, len);
snprintf(path, len, "%s%s%s%s", dir, SWITCH_PATH_SEPARATOR, file, ext);
switch_snprintf(path, len, "%s%s%s%s", dir, SWITCH_PATH_SEPARATOR, file, ext);
}
}
@@ -1592,7 +1592,7 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
JS_ResumeRequest(cx, cb_state.saveDepth);
*rval = cb_state.ret;
snprintf(posbuf, sizeof(posbuf), "%u", fh.offset_pos);
switch_snprintf(posbuf, sizeof(posbuf), "%u", fh.offset_pos);
switch_channel_set_variable(channel, "last_file_position", posbuf);
return JS_TRUE;
@@ -2175,7 +2175,7 @@ static size_t hash_callback(void *ptr, size_t size, size_t nmemb, void *data)
for (p = val + strlen(val) - 1; *p == ' '; p--)
*p = '\0';
snprintf(code, sizeof(code), "~%s[\"%s\"] = \"%s\"", config_data->name, line, val);
switch_snprintf(code, sizeof(code), "~%s[\"%s\"] = \"%s\"", config_data->name, line, val);
eval_some_js(code, config_data->cx, config_data->obj, &rval);
}
@@ -2374,7 +2374,7 @@ static JSBool js_fetchurl(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, config_data.buffer));
} else {
char errmsg[256];
snprintf(errmsg, 256, "~throw new Error(\"Curl returned error %u.\");", (unsigned)code);
switch_snprintf(errmsg, 256, "~throw new Error(\"Curl returned error %u.\");", (unsigned)code);
eval_some_js(errmsg, cx, obj, rval);
}
@@ -2974,7 +2974,7 @@ static JSBool js_exit(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
char *supplied_error, code_buf[256] = "";
if (argc > 0 && (supplied_error = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
snprintf(code_buf, sizeof(code_buf), "~throw new Error(\"%s\");", supplied_error);
switch_snprintf(code_buf, sizeof(code_buf), "~throw new Error(\"%s\");", supplied_error);
eval_some_js(code_buf, cx, obj, rval);
}
@@ -3271,7 +3271,7 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp
/* Emaculent conception of session object into the script if one is available */
if (!(session && new_js_session(cx, javascript_global_object, session, &jss, "session", flags))) {
snprintf(buf, sizeof(buf), "~var session = false;");
switch_snprintf(buf, sizeof(buf), "~var session = false;");
eval_some_js(buf, cx, javascript_global_object, &rval);
}
if (ro) {
@@ -3291,17 +3291,17 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp
}
if (!argc) {
snprintf(buf, sizeof(buf), "~var argv = new Array();");
switch_snprintf(buf, sizeof(buf), "~var argv = new Array();");
eval_some_js(buf, cx, javascript_global_object, &rval);
} else {
/* create a js doppleganger of this argc/argv */
snprintf(buf, sizeof(buf), "~var argv = new Array(%d);", argc);
switch_snprintf(buf, sizeof(buf), "~var argv = new Array(%d);", argc);
eval_some_js(buf, cx, javascript_global_object, &rval);
snprintf(buf, sizeof(buf), "~var argc = %d", argc);
switch_snprintf(buf, sizeof(buf), "~var argc = %d", argc);
eval_some_js(buf, cx, javascript_global_object, &rval);
for (y = 0; y < argc; y++) {
snprintf(buf, sizeof(buf), "~argv[%d] = \"%s\";", x++, argv[y]);
switch_snprintf(buf, sizeof(buf), "~argv[%d] = \"%s\";", x++, argv[y]);
eval_some_js(buf, cx, javascript_global_object, &rval);
}
}

View File

@@ -113,18 +113,18 @@ static int db_callback(void *pArg, int argc, char **argv, char **columnNames)
jsval rval;
int x = 0;
snprintf(code, sizeof(code), "~var _Db_RoW_ = {}");
switch_snprintf(code, sizeof(code), "~var _Db_RoW_ = {}");
eval_some_js(code, dbo->cx, dbo->obj, &rval);
for (x = 0; x < argc; x++) {
snprintf(code, sizeof(code), "~_Db_RoW_[\"%s\"] = \"%s\"", columnNames[x], argv[x]);
switch_snprintf(code, sizeof(code), "~_Db_RoW_[\"%s\"] = \"%s\"", columnNames[x], argv[x]);
eval_some_js(code, dbo->cx, dbo->obj, &rval);
}
snprintf(code, sizeof(code), "~%s(_Db_RoW_)", dbo->code_buffer);
switch_snprintf(code, sizeof(code), "~%s(_Db_RoW_)", dbo->code_buffer);
eval_some_js(code, dbo->cx, dbo->obj, &rval);
snprintf(code, sizeof(code), "~delete _Db_RoW_");
switch_snprintf(code, sizeof(code), "~delete _Db_RoW_");
eval_some_js(code, dbo->cx, dbo->obj, &rval);
return 0;
@@ -208,13 +208,13 @@ static JSBool db_fetch(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
return JS_FALSE;
}
snprintf(code, sizeof(code), "~var _dB_RoW_DaTa_ = {}");
switch_snprintf(code, sizeof(code), "~var _dB_RoW_DaTa_ = {}");
eval_some_js(code, dbo->cx, dbo->obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
}
for (x = 0; x < colcount; x++) {
snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
switch_snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
(char *) switch_core_db_column_name(dbo->stmt, x), (char *) switch_core_db_column_text(dbo->stmt, x));
eval_some_js(code, dbo->cx, dbo->obj, rval);

View File

@@ -359,7 +359,7 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *a
SQLLEN m = 0;
char code[66560];
snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
switch_snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
eval_some_js(code, cx, obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
@@ -383,7 +383,7 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *a
data = esc;
}
snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
switch_snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
switch_safe_free(esc);
eval_some_js((char *) odbc_obj->code, cx, obj, rval);