ZhengweiZhu commented on code in PR #3158:
URL: https://github.com/apache/brpc/pull/3158#discussion_r2548905760


##########
src/bthread/types.h:
##########
@@ -118,6 +120,12 @@ typedef struct bthread_attr_t {
         return tmp;
     }
 #endif  // __cplusplus
+    void set_name(const char* val) {
+        if (val) {
+            strncpy(name, val, BTHREAD_NAME_MAX_LENGTH);
+            name[BTHREAD_NAME_MAX_LENGTH] = '\0';

Review Comment:
   1. Where bthread_attr_t is used, where the predefined static constants like 
'BTHREAD_ATTR_*' is used. I have not seen any code constructing bthread_attr_t 
manually and no reason to do so.
   2. Even if  'BTHREAD_ATTR_*' is not used, current implementation also 
handles well. when the bthread name is set by user, the string be copied should 
be null terminated. if the string exceeds BTHREAD_NAME_MAX_LENGTH, then 
name[BTHREAD_NAME_MAX_LENGTH] = '\0'; works to avoid buffer overflow. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to