Skip to content

Commit

Permalink
Fix sql_ascii_escape_and_quote
Browse files Browse the repository at this point in the history
Added the missing exceptions params and fixed the g_free of
escaped_string.
  • Loading branch information
timopollmeier committed Jul 23, 2024
1 parent f6b6ade commit fa798e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,9 @@ make_tls_certificate_214 (user_t owner,
quoted_certificate_b64
= certificate_b64 ? sql_quote (certificate_b64) : NULL;
quoted_subject_dn
= subject_dn ? sql_ascii_escape_and_quote (subject_dn) : NULL;
= subject_dn ? sql_ascii_escape_and_quote (subject_dn, NULL) : NULL;

Check warning on line 855 in src/manage_migrators.c

View check run for this annotation

Codecov / codecov/patch

src/manage_migrators.c#L855

Added line #L855 was not covered by tests
quoted_issuer_dn
= issuer_dn ? sql_ascii_escape_and_quote (issuer_dn) : NULL;
= issuer_dn ? sql_ascii_escape_and_quote (issuer_dn, NULL) : NULL;

Check warning on line 857 in src/manage_migrators.c

View check run for this annotation

Codecov / codecov/patch

src/manage_migrators.c#L857

Added line #L857 was not covered by tests
quoted_md5_fingerprint
= md5_fingerprint ? sql_quote (md5_fingerprint) : NULL;
quoted_sha256_fingerprint
Expand Down
14 changes: 8 additions & 6 deletions src/manage_sql_tls_certificates.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ make_tls_certificate (const char *name,
quoted_sha256_fingerprint
= sql_quote (sha256_fingerprint ? sha256_fingerprint : "");
quoted_subject_dn
= sql_ascii_escape_and_quote (subject_dn ? subject_dn : "");
= sql_ascii_escape_and_quote (subject_dn ? subject_dn : "", NULL);

Check warning on line 588 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L588

Added line #L588 was not covered by tests
quoted_issuer_dn
= sql_ascii_escape_and_quote (issuer_dn ? issuer_dn : "");
= sql_ascii_escape_and_quote (issuer_dn ? issuer_dn : "", NULL);

Check warning on line 590 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L590

Added line #L590 was not covered by tests
quoted_serial
= sql_quote (serial ? serial : "");

Expand Down Expand Up @@ -1747,8 +1747,10 @@ cleanup_tls_certificate_encoding ()
if (g_utf8_validate (subject_dn, -1, NULL) == FALSE
|| g_utf8_validate (issuer_dn, -1, NULL) == FALSE)
{
gchar *quoted_subject_dn = sql_ascii_escape_and_quote (subject_dn);
gchar *quoted_issuer_dn = sql_ascii_escape_and_quote (issuer_dn);
gchar *quoted_subject_dn
= sql_ascii_escape_and_quote (subject_dn, NULL);

Check warning on line 1751 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L1751

Added line #L1751 was not covered by tests
gchar *quoted_issuer_dn
= sql_ascii_escape_and_quote (issuer_dn, NULL);

Check warning on line 1753 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L1753

Added line #L1753 was not covered by tests

sql ("UPDATE tls_certificates"
" SET subject_dn = '%s', issuer_dn = '%s'"
Expand Down Expand Up @@ -1779,8 +1781,8 @@ cleanup_tls_certificate_encoding ()
subject_dn = iterator_string (&iterator, 1);
issuer_dn = iterator_string (&iterator, 2);

Check warning on line 1782 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L1780-L1782

Added lines #L1780 - L1782 were not covered by tests

gchar *quoted_subject_dn = sql_ascii_escape_and_quote (subject_dn);
gchar *quoted_issuer_dn = sql_ascii_escape_and_quote (issuer_dn);
gchar *quoted_subject_dn = sql_ascii_escape_and_quote (subject_dn, NULL);
gchar *quoted_issuer_dn = sql_ascii_escape_and_quote (issuer_dn, NULL);

Check warning on line 1785 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L1784-L1785

Added lines #L1784 - L1785 were not covered by tests

sql ("UPDATE tls_certificates"

Check warning on line 1787 in src/manage_sql_tls_certificates.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_tls_certificates.c#L1787

Added line #L1787 was not covered by tests
" SET subject_dn = '%s', issuer_dn = '%s'"
Expand Down
6 changes: 3 additions & 3 deletions src/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ sql_quote (const char* string)
* @return Freshly allocated, quoted string. Free with g_free.
*/
gchar*
sql_ascii_escape_and_quote (const char* string)
sql_ascii_escape_and_quote (const char* string, const char* exceptions)

Check warning on line 164 in src/sql.c

View check run for this annotation

Codecov / codecov/patch

src/sql.c#L164

Added line #L164 was not covered by tests
{
gchar *escaped_string;
gchar *quoted_string;
Expand All @@ -171,9 +171,9 @@ sql_ascii_escape_and_quote (const char* string)
if (string == NULL)
return NULL;

Check warning on line 172 in src/sql.c

View check run for this annotation

Codecov / codecov/patch

src/sql.c#L172

Added line #L172 was not covered by tests

escaped_string = strescape_check_utf8 (string, NULL);
escaped_string = strescape_check_utf8 (string, exceptions);
quoted_string = sql_quote (escaped_string);
g_free (quoted_string);
g_free (escaped_string);

Check warning on line 176 in src/sql.c

View check run for this annotation

Codecov / codecov/patch

src/sql.c#L174-L176

Added lines #L174 - L176 were not covered by tests

return quoted_string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ gchar *
sql_quote (const char *);

gchar *
sql_ascii_escape_and_quote (const char *);
sql_ascii_escape_and_quote (const char *, const char *);

gchar *
sql_insert (const char *);
Expand Down

0 comments on commit fa798e8

Please sign in to comment.