Skip to content
/ server Public

MDEV-38010: Fix trailing garbage in master.info numeric fields#4764

Open
ayush-jha123 wants to merge 1 commit intoMariaDB:10.11from
ayush-jha123:fix-branch-10.11
Open

MDEV-38010: Fix trailing garbage in master.info numeric fields#4764
ayush-jha123 wants to merge 1 commit intoMariaDB:10.11from
ayush-jha123:fix-branch-10.11

Conversation

@ayush-jha123
Copy link

I've updated this PR to target the 10.11 branch as requested and added a test case to verify the fix.

The issue was that

init_intvar_from_file
and
init_floatvar_from_file
were using atoi or simple sscanf, which would stop parsing at the first non-numeric character and leave the remaining "garbage" in the buffer. This garbage then corrupted the start of the next line.

I've changed the logic to use strtol and sscanf with %n to track exactly where parsing ends. Now, the code checks the rest of the line; if there's any non-whitespace characters left (like 3306abcdef), it returns an error instead of proceeding with a broken configuration.
The new MTR test main.mdev_38010 simulates a malformed master.info and confirms the server fails to load it, falling back to default values instead of accepting junk data.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 10, 2026
@gkodinov
Copy link
Member

See also #4752

Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have done the target branch replace in-PR. But OK, I've closed the other one. Hope that's OK.

Please fix the msan failure. And also use the mysys functions please.

while (my_isspace(&my_charset_bin, *endptr))
endptr++;
if (*endptr != '\0')
DBUG_RETURN(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you need to assign something to *var here. Otherwise msan complains.

sql/slave.cc Outdated
{
*var = atoi(buf);
char *endptr;
long val= strtol(buf, &endptr, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use my_strtol.

sql/slave.cc Outdated
{
if (sscanf(buf, "%f", var) != 1)
int bytes_read= 0;
if (sscanf(buf, "%f%n", var, &bytes_read) != 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use my_strtod()

@ayush-jha123 ayush-jha123 force-pushed the fix-branch-10.11 branch 5 times, most recently from eb5cd72 to 9d39733 Compare March 11, 2026 19:01
@ayush-jha123
Copy link
Author

@gkodinov Thank you for your patience and the helpful feedback

I have incorporated all the requested changes:

  1. Switched out standard strtol / sscanf for MariaDB's internal my_strtoll10 and my_strtod.
  2. Fixed the MSan use-of-uninitialized-value warnings. I discovered that my_strtoll10 expects endptr to define the buffer boundary, so initializing it to buf + strlen(buf) resolved the parsing aborts.
  3. Explicitly zero-initialized variables in the Master_info constructor so that even if master.info parsing intentionally aborts on a corrupted file (like in mdev_38010), SHOW SLAVE STATUS safely reads initialized data.

After several iterations to iron out the CI regressions, all tests (including MSan and replication runs) are now passing successfuly

Please let me know if there are any further modifications needed or if this looks good to go.

Copy link
Contributor

@ParadoxV5 ParadoxV5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update your patch to the latest 10.11 branch and factor in MDEV-38020 (#4701)’s init_ulonglongvar_from_file()

sql/rpl_mi.cc Outdated
semi_sync_reply_enabled(0)
{
char *tmp;
master_log_name[0] = 0; master_log_pos = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must’ve missed the need. What’s this addition doing here?

sql/slave.cc Outdated
Comment on lines +1603 to +1617
if (error && error != MY_ERRNO_EDOM)
DBUG_RETURN(1);

while (my_isspace(&my_charset_latin1, *endptr))
endptr++;
if (*endptr != '\0')
DBUG_RETURN(1);

if (error != MY_ERRNO_EDOM)
*var= (int) val;


DBUG_RETURN(0);
}
DBUG_RETURN(1);
DBUG_RETURN(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Why would MY_ERRNO_EDOM default the field with no error?…
    Oh, I know: That’s MDEV-38020’s job. And it has been merged.
  • Why bother removing trailing spaces?
    I wouldn’t, except for the line break.
  • If we’re reordering the flow, we might as well merge the two DBUG_RETURN(0);s.

These comments also apply to init_floatvar_from_file() below.

@ParadoxV5 ParadoxV5 requested a review from bnestere March 12, 2026 18:48
@ParadoxV5 ParadoxV5 added the Replication Patches involved in replication label Mar 12, 2026
Modified init_intvar_from_file and init_floatvar_from_file to detect and reject trailing garbage in master.info numeric fields. Added a test case to verify the fix and ensure replication is correctly restored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. Replication Patches involved in replication

Development

Successfully merging this pull request may close these issues.

3 participants