Bug#1019624: UPSONIC IRT-3K 2U broken by length checking in blazer_usb/nutdrv_qx

2022-10-23 Thread Trent W. Buck
On Fri 21 Oct 2022 21:35:18 +0200, Laurent Bigonville wrote:
> On Tue, 13 Sep 2022 10:19:24 +1000 "Trent W. Buck" 
> wrote:
> Hello,
> >
> > Short version:
> >
> > 1. UPSONIC IRT-3K 2U speaks a variant of Q1 which omits final \r.
> > 2. nut 2.4 doesn't check for final \r, so it Just Works.
> > 3. nut 2.7 checks for final \r, cannot talk to my UPS.
> > 4. I fixed #3 but it's not very good.
> 
> Do you think you could check whether nut 2.8.0 (currently in unstable) works
> with your UPS?

That UPS is currently in production, so I can't easily mess with it.
I also do not have a spare.

However, I did find this which looks like the same bug:

https://github.com/networkupstools/nut/issues/441
https://github.com/zykh/nut/commit/1595a06501daa93e06035a861e3db7ccab2871dd

I don't know how I missed this earlier.

> Otherwise if the bug is still happening, could you please open a bug
> upstream if it's not already done?

I'm happy enough to mark this as done in sid.
When Debian 12 ships, if I run into this again, I'll reopen it.

I added a comment upstream:

https://github.com/networkupstools/nut/issues/441#issuecomment-1288238345



Bug#1019624: UPSONIC IRT-3K 2U broken by length checking in blazer_usb/nutdrv_qx

2022-10-21 Thread Laurent Bigonville
On Tue, 13 Sep 2022 10:19:24 +1000 "Trent W. Buck"  
wrote:

Hello,
>
> Short version:
>
> 1. UPSONIC IRT-3K 2U speaks a variant of Q1 which omits final \r.
> 2. nut 2.4 doesn't check for final \r, so it Just Works.
> 3. nut 2.7 checks for final \r, cannot talk to my UPS.
> 4. I fixed #3 but it's not very good.

Do you think you could check whether nut 2.8.0 (currently in unstable) 
works with your UPS?


Otherwise if the bug is still happening, could you please open a bug 
upstream if it's not already done?


Kind regards,

Laurent Bigonville



Bug#1019624: UPSONIC IRT-3K 2U broken by length checking in blazer_usb/nutdrv_qx

2022-09-12 Thread Trent W. Buck
Package: nut-server
Version: 2.7.4-13
Severity: normal
Tags: patch

Short version:

  1. UPSONIC IRT-3K 2U speaks a variant of Q1 which omits final \r.
  2. nut 2.4 doesn't check for final \r, so it Just Works.
  3. nut 2.7 checks for final \r, cannot talk to my UPS.
  4. I fixed #3 but it's not very good.


Boring detailed version follows.

I have an "UPSONIC IRT-3K 2U" UPS.
Until September 2022, I was talking to it over USB using nut 2.4, using the 
megatec_usb driver.
This worked fine.

root@omega:~# dpkg-query -W nut
nut 2.4.3-1ubuntu3.2

root@omega:~# grep -v ^# /etc/nut/ups.conf
[upset]
driver = megatec_usb
port = unused

root@omega:~# xzgrep -hF 'omega upslog [upset]: OL '  
/srv/log/syslog-20220824.xz  | tail -n1
2022-08-24T06:45:44.154096+10:00 omega upslog [upset]: OL 87.3% charge, 
50.0% load, 18.0°C, 50.0Hz 228.0V in, 240.0V out

I upgraded the nut server to Debian 11 / nut 2.7, using the blazer_usb driver.
There, I got errors from the F\r and I\r queries:

cyber@light:~$ sudo /lib/nut/blazer_usb -a upset -DDD
...
1.169169 send: F
1.313636 received 21 (35)
1.313660 read: #240.0 014 72.00 50.0
1.313668 blazer_rating: short reply
1.313675 Rating read 3 failed
1.313688 Rating information unavailable
...
1.753885 send: I
1.976101 received 38 (35)
1.976125 read: #UPSONIC IRT-3K 2U  MP001155
1.976133 blazer_vendor: short reply
1.976139 Vendor information read 3 failed
1.976146 Vendor information unavailable

Using driver=nutdrv_qx, the Q1\r query also fails in the same way (short reply).

I think this is happening because, for some reason, UPSONIC omits the trailing 
\r from its responses.
I think:

1. megatec_usb.c in nut 2.4 (omega) did not length-check anything, so all 3 
queries worked.
2. blazer_usb.c in nut 2.7 (light) length-checks I and F but not Q1, so 
only Q1 works (thus also breaking charge percentage ).
3. nutdrv_qx in nut 2.7 (light) length-checks all 3 queries, so all 3 
queries fail.

I have forked the nutdrv_qx_megatec.c to a nutdrv_qx_upsonic.c and simply 
dropped the number of bytes to read by 1.
This is now working perfectly:

cyber@light:~$ sudo ./nutdrv_qx_cyber -a upset -DDD -x protocol=upsonic -x 
subdriver=krauler -x vendorid= -x productid=
Network UPS Tools - Generic Q* USB/Serial driver 0.28 (2.7.4)
USB communication driver 0.33
   0.00 debug level is '3'
   0.000744 upsdrv_initups...
   0.341199 Checking device (1D6B/0003) (006/001)
   0.372926 - VendorID: 1d6b
   0.372937 - ProductID: 0003
   0.372942 - Manufacturer: unknown
   0.372945 - Product: unknown
   0.372949 - Serial Number: unknown
   0.372952 - Bus: 006
   0.372955 - Device release number: 0510
   0.372959 Trying to match device
   0.372966 Device does not match - skipping
   0.372983 Checking device (1D6B/0002) (005/001)
   0.373132 - VendorID: 1d6b
   0.373153 - ProductID: 0002
   0.373162 - Manufacturer: unknown
   0.373168 - Product: unknown
   0.373175 - Serial Number: unknown
   0.373180 - Bus: 005
   0.373186 - Device release number: 0510
   0.373192 Trying to match device
   0.373201 Device does not match - skipping
   0.373217 Checking device (8087/0024) (003/002)
   0.442033 - VendorID: 8087
   0.442055 - ProductID: 0024
   0.442062 - Manufacturer: unknown
   0.442068 - Product: unknown
   0.442074 - Serial Number: unknown
   0.442079 - Bus: 003
   0.442085 - Device release number: 
   0.442094 Trying to match device
   0.442104 Device does not match - skipping
   0.442119 Checking device (1D6B/0002) (003/001)
   0.442157 - VendorID: 1d6b
   0.442167 - ProductID: 0002
   0.442176 - Manufacturer: unknown
   0.442182 - Product: unknown
   0.442189 - Serial Number: unknown
   0.442195 - Bus: 003
   0.442202 - Device release number: 0510
   0.442210 Trying to match device
   0.442218 Device does not match - skipping
   0.442230 Checking device (1D6B/0003) (004/001)
   0.468898 - VendorID: 1d6b
   0.468920 - ProductID: 0003
   0.468928 - Manufacturer: unknown
   0.468934 - Product: unknown
   0.468940 - Serial Number: unknown
   0.468946 - Bus: 004
   0.468954 - Device release number: 0510
   0.468962 Trying to match device
   0.468971 Device does not match - skipping
   0.468986 Checking device (1D6B/0002) (002/001)
   0.469174 - VendorID: 1d6b
   0.469195 - ProductID: 0002
   0.469203 - Manufacturer: unknown
   0.469209 - Product: unknown
   0.469214 - Serial