Skip to content

Commit

Permalink
Remove tained usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vhermecz committed Jan 31, 2023
1 parent 80f57fa commit c38d182
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions ext/odbc.c
Expand Up @@ -1371,7 +1371,7 @@ mkutf(char *dest, SQLWCHAR *src, int len)
}

static VALUE
uc_tainted_str_new(SQLWCHAR *str, int len)
uc_str_new(SQLWCHAR *str, int len)
{
VALUE v;
char *cp = xmalloc(len * 6 + 1);
Expand All @@ -1380,7 +1380,7 @@ uc_tainted_str_new(SQLWCHAR *str, int len)
if ((cp != NULL) && (str != NULL)) {
ulen = mkutf(cp, str, len);
}
v = rb_tainted_str_new((cp != NULL) ? cp : "", ulen);
v = rb_str_new((cp != NULL) ? cp : "", ulen);
#ifdef USE_RB_ENC
rb_enc_associate(v, rb_enc);
#endif
Expand All @@ -1391,9 +1391,9 @@ uc_tainted_str_new(SQLWCHAR *str, int len)
}

static VALUE
uc_tainted_str_new2(SQLWCHAR *str)
uc_str_new2(SQLWCHAR *str)
{
return uc_tainted_str_new(str, uc_strlen(str));
return uc_str_new(str, uc_strlen(str));
}

static VALUE
Expand Down Expand Up @@ -1870,7 +1870,7 @@ set_err(const char *msg, int warn)
rb_enc_associate(v, rb_enc);
#endif
a = rb_ary_new2(1);
rb_ary_push(a, rb_obj_taint(v));
rb_ary_push(a, (v));
CVAR_SET(Cobj, warn ? IDatatinfo : IDataterror, a);
return STR2CSTR(v);
}
Expand Down Expand Up @@ -1949,7 +1949,7 @@ get_err_or_info(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, int isinfo)
v0 = v;
a = rb_ary_new();
}
rb_ary_push(a, rb_obj_taint(v));
rb_ary_push(a, (v));
tracemsg(1, fprintf(stderr, " | %s\n", STR2CSTR(v)););
}
}
Expand Down Expand Up @@ -2045,7 +2045,7 @@ get_installer_err()
v0 = v;
a = rb_ary_new();
}
rb_ary_push(a, rb_obj_taint(v));
rb_ary_push(a, (v));
tracemsg(1, fprintf(stderr, " | %s\n", STR2CSTR(v)););
}
}
Expand Down Expand Up @@ -2299,7 +2299,7 @@ dbc_raise(VALUE self, VALUE msg)
buf[SQL_MAX_MESSAGE_LENGTH] = '\0';
v = rb_str_new2(buf);
a = rb_ary_new2(1);
rb_ary_push(a, rb_obj_taint(v));
rb_ary_push(a, (v));
CVAR_SET(Cobj, IDataterror, a);
rb_raise(Cerror, "%s", buf);
return Qnil;
Expand Down Expand Up @@ -2384,13 +2384,13 @@ dbc_dsns(VALUE self)
descrLen = (descrLen == 0) ?
(SQLSMALLINT) uc_strlen(descr) :
(SQLSMALLINT) (descrLen / sizeof (SQLWCHAR));
rb_iv_set(odsn, "@name", uc_tainted_str_new(dsn, dsnLen));
rb_iv_set(odsn, "@descr", uc_tainted_str_new(descr, descrLen));
rb_iv_set(odsn, "@name", uc_str_new(dsn, dsnLen));
rb_iv_set(odsn, "@descr", uc_str_new(descr, descrLen));
#else
dsnLen = (dsnLen == 0) ? (SQLSMALLINT) strlen(dsn) : dsnLen;
descrLen = (descrLen == 0) ? (SQLSMALLINT) strlen(descr) : descrLen;
rb_iv_set(odsn, "@name", rb_tainted_str_new(dsn, dsnLen));
rb_iv_set(odsn, "@descr", rb_tainted_str_new(descr, descrLen));
rb_iv_set(odsn, "@name", rb_str_new(dsn, dsnLen));
rb_iv_set(odsn, "@descr", rb_str_new(descr, descrLen));
#endif
rb_ary_push(aret, odsn);
first = dsnLen = descrLen = 0;
Expand Down Expand Up @@ -2440,27 +2440,27 @@ dbc_drivers(VALUE self)
driverLen = (driverLen == 0) ?
(SQLSMALLINT) uc_strlen(driver) :
(SQLSMALLINT) (driverLen / sizeof (SQLWCHAR));
rb_iv_set(odrv, "@name", uc_tainted_str_new(driver, driverLen));
rb_iv_set(odrv, "@name", uc_str_new(driver, driverLen));
for (attr = attrs; *attr; attr += uc_strlen(attr) + 1) {
SQLWCHAR *p = uc_strchr(attr, (SQLWCHAR) '=');

if ((p != NULL) && (p != attr)) {
rb_hash_aset(h,
uc_tainted_str_new(attr, (p - attr) /
uc_str_new(attr, (p - attr) /
sizeof (SQLWCHAR)),
uc_tainted_str_new2(p + 1));
uc_str_new2(p + 1));
count++;
}
}
#else
driverLen = (driverLen == 0) ? (SQLSMALLINT) strlen(driver) : driverLen;
rb_iv_set(odrv, "@name", rb_tainted_str_new(driver, driverLen));
rb_iv_set(odrv, "@name", rb_str_new(driver, driverLen));
for (attr = attrs; *attr; attr += strlen(attr) + 1) {
char *p = strchr(attr, '=');

if ((p != NULL) && (p != attr)) {
rb_hash_aset(h, rb_tainted_str_new(attr, p - attr),
rb_tainted_str_new2(p + 1));
rb_hash_aset(h, rb_str_new(attr, p - attr),
rb_str_new2(p + 1));
count++;
}
}
Expand Down Expand Up @@ -2759,7 +2759,7 @@ dbc_rfdsn(int argc, VALUE *argv, VALUE self)
uc_free(saname);
uc_free(skname);
if (rc) {
return uc_tainted_str_new2(valbuf);
return uc_str_new2(valbuf);
}
} else {
sfname = (SQLWCHAR *) STR2CSTR(fname);
Expand All @@ -2769,7 +2769,7 @@ dbc_rfdsn(int argc, VALUE *argv, VALUE self)
if (SQLReadFileDSN((LPCSTR) sfname, (LPCSTR) saname,
(LPCSTR) skname, (LPSTR) valbuf,
sizeof (valbuf), NULL)) {
return rb_tainted_str_new2((char *) valbuf);
return rb_str_new2((char *) valbuf);
}
}
#else
Expand All @@ -2779,7 +2779,7 @@ dbc_rfdsn(int argc, VALUE *argv, VALUE self)
valbuf[0] = '\0';
if (SQLReadFileDSN(sfname, saname, skname, valbuf,
sizeof (valbuf), NULL)) {
return rb_tainted_str_new2(valbuf);
return rb_str_new2(valbuf);
}
#endif
#if defined(HAVE_SQLINSTALLERERROR) || (defined(UNICODE) && defined(HAVE_SQLINSTALLERERRORW))
Expand Down Expand Up @@ -4574,7 +4574,7 @@ make_column(SQLHSTMT hstmt, int i, int upc, int use_scn)
len = 0;
}
mkutf(tmp, name, len);
v = rb_tainted_str_new2(upcase_if(tmp, 1));
v = rb_str_new2(upcase_if(tmp, 1));
#ifdef USE_RB_ENC
rb_enc_associate(v, rb_enc);
#endif
Expand All @@ -4583,10 +4583,10 @@ make_column(SQLHSTMT hstmt, int i, int upc, int use_scn)
xfree(tmp);
}
} else {
rb_iv_set(obj, "@name", uc_tainted_str_new2(name));
rb_iv_set(obj, "@name", uc_str_new2(name));
}
#else
rb_iv_set(obj, "@name", rb_tainted_str_new2(upcase_if(name, upc)));
rb_iv_set(obj, "@name", rb_str_new2(upcase_if(name, upc)));
#endif
v = Qnil;
name[0] = 0;
Expand All @@ -4602,9 +4602,9 @@ make_column(SQLHSTMT hstmt, int i, int upc, int use_scn)
name[name_len / sizeof (name[0])] = 0;
}
#ifdef UNICODE
v = uc_tainted_str_new2(name);
v = uc_str_new2(name);
#else
v = rb_tainted_str_new2(name);
v = rb_str_new2(name);
#endif
}
rb_iv_set(obj, "@table", v);
Expand Down Expand Up @@ -6699,12 +6699,12 @@ stmt_param_output_value(int argc, VALUE *argv, VALUE self)
break;
#ifdef UNICODE
case SQL_C_WCHAR:
v = uc_tainted_str_new((SQLWCHAR *) q->paraminfo[vnum].outbuf,
v = uc_str_new((SQLWCHAR *) q->paraminfo[vnum].outbuf,
q->paraminfo[vnum].rlen / sizeof (SQLWCHAR));
break;
#endif
case SQL_C_CHAR:
v = rb_tainted_str_new(q->paraminfo[vnum].outbuf,
v = rb_str_new(q->paraminfo[vnum].outbuf,
q->paraminfo[vnum].rlen);
break;
}
Expand Down Expand Up @@ -6777,10 +6777,10 @@ stmt_cursorname(int argc, VALUE *argv, VALUE self)
#ifdef UNICODE
cnLen = (cnLen == 0) ? (SQLSMALLINT) uc_strlen(cname) :
(SQLSMALLINT) (cnLen / sizeof (SQLWCHAR));
return uc_tainted_str_new(cname, cnLen);
return uc_str_new(cname, cnLen);
#else
cnLen = (cnLen == 0) ? (SQLSMALLINT) strlen((char *) cname) : cnLen;
return rb_tainted_str_new((char *) cname, cnLen);
return rb_str_new((char *) cname, cnLen);
#endif
}
if (TYPE(cn) != T_STRING) {
Expand Down Expand Up @@ -6866,7 +6866,7 @@ stmt_columns(int argc, VALUE *argv, VALUE self)

sprintf(buf, "#%d", i);
name = rb_str_dup(name);
name = rb_obj_taint(rb_str_cat2(name, buf));
name = (rb_str_cat2(name, buf));
}
rb_hash_aset(res, name, obj);
}
Expand Down Expand Up @@ -7115,15 +7115,15 @@ do_fetch(STMT *q, int mode)
}
for (i = 0; i < 4 * q->ncols; i++) {
res = colbuf[i / q->ncols];
cname = rb_tainted_str_new2(q->colnames[i]);
cname = rb_str_new2(q->colnames[i]);
#ifdef USE_RB_ENC
rb_enc_associate(cname, rb_enc);
#endif
q->colvals[i] = cname;
if (rb_funcall(res, IDkeyp, 1, cname) == Qtrue) {
char *p;

cname = rb_tainted_str_new2(q->colnames[i]);
cname = rb_str_new2(q->colnames[i]);
#ifdef USE_RB_ENC
rb_enc_associate(cname, rb_enc);
#endif
Expand Down Expand Up @@ -7359,12 +7359,12 @@ do_fetch(STMT *q, int mode)
break;
#ifdef UNICODE
case SQL_C_WCHAR:
v = uc_tainted_str_new((SQLWCHAR *) valp,
v = uc_str_new((SQLWCHAR *) valp,
curlen / sizeof (SQLWCHAR));
break;
#endif
default:
v = rb_tainted_str_new(valp, curlen);
v = rb_str_new(valp, curlen);
break;
}
}
Expand All @@ -7377,14 +7377,14 @@ do_fetch(STMT *q, int mode)
valp = q->colnames[i + offc];
name = (q->colvals == NULL) ? Qnil : q->colvals[i + offc];
if (name == Qnil) {
name = rb_tainted_str_new2(valp);
name = rb_str_new2(valp);
#ifdef USE_RB_ENC
rb_enc_associate(name, rb_enc);
#endif
if (rb_funcall(res, IDkeyp, 1, name) == Qtrue) {
char *p;

name = rb_tainted_str_new2(valp);
name = rb_str_new2(valp);
#ifdef USE_RB_ENC
rb_enc_associate(name, rb_enc);
#endif
Expand Down

0 comments on commit c38d182

Please sign in to comment.