Skip to content

Conversation

@yihaoDeng
Copy link
Contributor

Description

Please briefly describe the code changes in this pull request.

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yihaoDeng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves an error related to clearing user IP addresses by refining the internal mechanism for managing user-specific IP information. It introduces a dedicated field within the connection object to store user IP, ensuring its proper handling and separation from other connection details. Concurrently, the changes include an updated C example program that thoroughly demonstrates the correct usage of connection options for setting and clearing user IP, providing clearer output for verification.

Highlights

  • User IP Management Refinement: Introduced a dedicated userDualIp field within the SConnObj structure to explicitly manage user IP addresses, effectively separating it from the general connection address (addr). This change allows for more precise control over user-specific IP settings.
  • Enhanced Connection Option Example: Updated the connect_example.c C program to provide a more comprehensive demonstration of taos_options_connection. The example now showcases how to set, clear, and re-set user IP addresses using TSDB_OPTION_CONNECTION_USER_IP and the newly demonstrated TSDB_OPTION_CONNECTION_CLEAR option.
  • Improved Example Output: Added utility functions, printRow and printResult, to the C example. These functions facilitate clearer and more structured display of query results, making it easier to verify the state of connections after applying various IP settings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue with clearing the user IP by introducing a dedicated field for it and modifying the handling logic. While the core change appears correct, the updated example file (connect_example.c) has several critical issues, including potential buffer overflows, duplicated macro definitions, and a fall-through bug in a switch statement. These should be addressed to ensure the example code is safe and follows good practices.

static int printResult(TAOS_RES *res) {
int numFields = taos_num_fields(res);
TAOS_FIELD *fields = taos_fetch_fields(res);
char header[256] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The header buffer has a fixed size of 256 bytes. If the combined length of column names in a query result exceeds this limit, sprintf will write past the buffer's boundary, causing a buffer overflow. This is a critical security vulnerability. Consider using dynamic memory allocation to create a buffer of the required size.


TAOS_ROW row = NULL;
while ((row = taos_fetch_row(res))) {
char temp[256] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The temp buffer has a fixed size of 256 bytes. If the string representation of a single row, as formatted by printRow, exceeds this limit, a buffer overflow will occur. This is a critical security vulnerability. A safer approach would be to dynamically allocate memory for the buffer based on the actual required size.

Comment on lines 100 to 101
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The case TSDB_DATA_TYPE_BOOL: is missing a break statement. This causes an unintended fall-through to the default case, which could lead to incorrect behavior.

        len += sprintf(str + len, "%d", *((int8_t *)row[i]));
        break;
      default:

Comment on lines 19 to 25
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define TSDB_NCHAR_SIZE sizeof(int32_t)
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)

#define GET_FLOAT_VAL(x) (*(float *)(x))
#define GET_DOUBLE_VAL(x) (*(double *)(x))

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These macro definitions are duplicates of the ones in lines 13-17. Redundant code increases maintenance overhead and can lead to inconsistencies. Please remove these duplicated lines.

Comment on lines 150 to 165
{
{
TAOS_RES *res = taos_query(taos, "show connections");

printResult(res);
sleep(5);
if (taos == NULL) {
fprintf(stderr, "Failed to connect to %s:%hu, ErrCode: 0x%x, ErrMessage: %s.\n", host, port, taos_errno(NULL),
taos_errstr(NULL));
taos_cleanup();
return -1;
}

taos_free_result(res);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of code for querying connections and printing results is duplicated multiple times in the main function. To improve maintainability and reduce redundancy, this logic should be refactored into a separate helper function.

}

if (emptyIpRange(pRange)) return;
// if (emptyIpRange(pRange)) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Commenting out this safety check is risky. While it might be intended to handle clearing the user IP, it relies on the implicit behavior of tIpUintToStr when given an empty range. A safer and clearer approach would be to explicitly handle the empty range case to clear the userDualIp field. For example:

if (emptyIpRange(pRange)) {
    memset(&connObj->userDualIp, 0, sizeof(connObj->userDualIp));
    return;
}

@guanshengliang guanshengliang merged commit b375653 into main Oct 13, 2025
16 of 19 checks passed
@guanshengliang guanshengliang changed the title fix clear userip error fix: clearing user_ip in taos_options_connection does not take effect Oct 13, 2025
@guanshengliang guanshengliang deleted the fix/TD-38266-main branch October 13, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants