Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new constant called SYSTEM_PROCESS_NAME_BUFFER_LENGTH #10

Merged
merged 2 commits into from
Feb 16, 2021

Conversation

klueska
Copy link
Contributor

@klueska klueska commented Feb 16, 2021

Previously we were using the value of C.PR_SET_NAME to limit the size of
the buffer used to write the process name into when calling
'nvmlSystemGetProcessName()'. While this technically wouldn't cause a
buffer overrun, it limited the length of the process name by a
(somewhat) arbitrary amount since C.PR_SET_NAME is not meant to indicate
a maximum length for a process name, but rather an arbitrary code for
telling 'prctl()' to set the name for a process (which has nothing to do
with its length).

It was a clear oversight to use this random value as the buffer length.
In the new implementation we simply hard code a new variable called
SYSTEM_PROCESS_NAME_BUFFER_LENGTH to 256 (which is well more than the
actual maximum process name length on linux). Having a larger value
won't hurt anything, and will make it more portable if / when we decide
to start supporting windows.

@klueska klueska mentioned this pull request Feb 16, 2021
Copy link
Member

@elezar elezar left a comment

Choose a reason for hiding this comment

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

Thanks @klueska . One minor nit on the naming. Other nvml functions have constants such as NVML_SYSTEM_NVML_VERSION_BUFFER_SIZE, so we could consider something like:

NVML_SYSTEM_NVML_PROCESS_NAME_BUFFER_SIZE

instead of the quite generic PROC_NAME_MAX. Not a blocker though.

@klueska
Copy link
Contributor Author

klueska commented Feb 16, 2021

I was actually trying to make it reminiscent of PATH_MAX on linux. However, now that you point it out, I actually think it should just be an internal variable and not exported at all. It’s definitely not something that should be namespaced with NVML since it’s not part of the original NVML namespace, and it’s just an internal implementation detail at this point.

@klueska klueska changed the title Add new constant called PROC_NAME_MAX Add new constant called SYSTEM_PROCESS_NAME_BUFFER_LENGTH Feb 16, 2021
gen/nvml/const_gen.go Outdated Show resolved Hide resolved
gen/nvml/const_gen.go Show resolved Hide resolved
root and others added 2 commits February 16, 2021 14:53
Previously we were using the value of C.PR_SET_NAME to limit the size of
the buffer used to write the process name into when calling
'nvmlSystemGetProcessName()'. While this technically wouldn't cause a
buffer overrun, it limited the length of the process name by a
(somewhat) arbitrary amount since C.PR_SET_NAME is not meant to indicate
a maximum length for a process name, but rather an arbitrary code for
telling 'prctl()' to set the name for a process (which has nothing to do
with its length).

It was a clear oversight to use this random value as the buffer length.
In the new implementation we simply hard code a new variable called
SYSTEM_PROCESS_NAME_BUFFER_LENGTH to 256 (which is well more than the
actual maximum process name length on linux). Having a larger value
won't hurt anything, and will make it more portable if / when we decide
to start supporting windows.

Signed-off-by: Kevin Klues <[email protected]>
Signed-off-by: Kevin Klues <[email protected]>
@klueska klueska merged commit 07551ef into master Feb 16, 2021
@klueska klueska deleted the fix-proc-name-len branch February 16, 2021 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants