Skip to content

ntp-ntpd: Fixed unpacking of ntpq -p values#758

Merged
markuslf merged 1 commit intoLinuxfabrik:mainfrom
leo-pempera:patch-1
May 3, 2024
Merged

ntp-ntpd: Fixed unpacking of ntpq -p values#758
markuslf merged 1 commit intoLinuxfabrik:mainfrom
leo-pempera:patch-1

Conversation

@leo-pempera
Copy link
Copy Markdown
Contributor

@leo-pempera leo-pempera commented May 2, 2024

When the chosen ntp Server (maked by *) has one or more whitespaces in its name, the original parsing fails with too many values to unpack.

Example:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000
+mail.gunnarhofm 192.53.103.103   2 u  110  256  377    2.793   -0.228   0.157
-gps.s-buettgen. 131.188.3.222    2 u  164  256  377    3.311    0.129   0.534
+ntp1.kashra-ser 192.168.100.15   2 u  174  256  377   13.709   -0.834   0.278
-47.ip-51-75-67. 17.253.14.251    2 u  156  256  217    4.930   -0.049   0.111
*185.232.69.65 ( 79.133.44.146    2 u  232  256  377    0.398   -0.182   0.170

peer, refid, stratum, _type, when, poll, reach, delay, offset, jitter = line[1:].split()
ValueError: too many values to unpack (expected 10)

A fix is to directly access the variables after remote via a negative index, as every value after is properly sanitized.

I also removed all unused extracted variables.

When the chosen ntp Server (maked by *) has one or more whitespaces in its name, the original parsing fails with too many values to unpack.
Example:
'*185.232.69.65 ( 79.133.44.146    2 u  139  256  377    0.401    0.133   0.137'

peer, refid, stratum, _type, when, poll, reach, delay, offset, jitter = line[1:].split()
ValueError: too many values to unpack (expected 10)
@markuslf markuslf changed the title Fixed unpacking of ntpq -p values ntp-ntpd: Fixed unpacking of ntpq -p values May 3, 2024
@markuslf markuslf merged commit 675f4ba into Linuxfabrik:main May 3, 2024
@markuslf
Copy link
Copy Markdown
Member

markuslf commented May 3, 2024

Thank you. I also enhanced the unit tests.

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