Skip to content

Commit

Permalink
mx_mysql: Fix serious bug when fetching empty strings (length=0)
Browse files Browse the repository at this point in the history
MySQL will not mark empty strings truncated because the
length of an empty string is equal to 0 and it occupies 0 bytes
in MySQL.

So the error flag will never be set for zero length strings.

Since we need zero length strings to be \0 terminated we ignore
error conditions for string types.
  • Loading branch information
mariux committed May 29, 2015
1 parent a94080b commit 4c21afd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mx_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,6 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt)

r = &stmt->result;
for (col = 0; col < r->count; col++) {
if (!(r->data[col].is_error))
continue;

if (r->bind[col].buffer_type == MYSQL_TYPE_STRING) {
str = mx_calloc_forever(r->data[col].length + 1, sizeof(*str));

Expand All @@ -1012,6 +1009,9 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt)
continue;
}

if (!(r->data[col].is_error))
continue;

mx_log_debug("WARNING: result data returned in column with index %d was truncated. query was:", col);
mx_log_debug(" \\ %s", stmt->statement);
no_error = 0;
Expand Down

0 comments on commit 4c21afd

Please sign in to comment.