[Bug 1558109] Re: Incorrect calculation of string lengths

Daniel 1558109 at bugs.launchpad.net
Wed Mar 16 22:43:56 UTC 2016


Correction: I just realized that the uploaded variant1 is the simpler
version and variant2 the simple bugfix.

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to live-build in Ubuntu.
https://bugs.launchpad.net/bugs/1558109

Title:
  Incorrect calculation of string lengths

Status in live-build package in Ubuntu:
  New

Bug description:
  When calling lb_config with parameters like `--iso-volume`, the length
  of the string is not correctly determined. The argument in the
  following example is limited to 32 characters, but the code in
  `/usr/share/live/build/functions/defaults.sh` only allows 31
  characters:

  # trying with 33 characters -> fails as expected
  root at 53e16c910d1d:/tmp# lb config --iso-volume '123456789-123456789-123456789-123'
  [2016-03-16 15:21:05] lb_config --iso-volume 123456789-123456789-123456789-123
  P: Considering defaults defined in /etc/live/build.conf
  W: You have specified a value of LB_ISO_VOLUME that is too long; the maximum length is 32 characters.
  P: Updating config tree for a ubuntu/amd64 system
  W: You have specified a value of LB_ISO_VOLUME that is too long; the maximum length is 32 characters.

  # trying with 32 characters -> fails but should work
  root at 53e16c910d1d:/tmp# lb config --iso-volume '123456789-123456789-123456789-12'
  [2016-03-16 15:21:07] lb_config --iso-volume 123456789-123456789-123456789-12
  P: Considering defaults defined in /etc/live/build.conf
  W: You have specified a value of LB_ISO_VOLUME that is too long; the maximum length is 32 characters.
  P: Updating config tree for a ubuntu/amd64 system
  W: You have specified a value of LB_ISO_VOLUME that is too long; the maximum length is 32 characters.

  # trying with 31 characters -> works as expected
  root at 53e16c910d1d:/tmp# lb config --iso-volume '123456789-123456789-123456789-1'
  [2016-03-16 15:21:09] lb_config --iso-volume 123456789-123456789-123456789-1
  P: Considering defaults defined in /etc/live/build.conf
  P: Updating config tree for a ubuntu/amd64 system

  There are two reasons for this error:
   * The string is sent to `wc -c` using `echo` which adds an extra line end character to the string
   * three of four tests surround their string by escaped " characters which are also counted. For LB_ISO_VOLUME, the developer tried to fix this using the `eval` function

  Additionally, the code is unnecessarily complex. Both dash and bash
  provide the `$#variable` syntax for getting the string length

  I add two patches, one fixes the problem and the second one contains
  the (simpler) alternative alternative syntax which works similar.

  Tested with live-build from 3.0~a57-1ubuntu22 from ubuntu wily but the
  current 3.0~a57-1ubuntu25 from xenial contains the same code

  
  root at 53e16c910d1d:/# dpkg -l live-build
  Desired=Unknown/Install/Remove/Purge/Hold
  | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
  |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
  ||/ Name                                                        Version                            Architecture                       Description
  +++-===========================================================-==================================-==================================-===========================================================================================================================
  ii  live-build                                                  3.0~a57-1ubuntu22                  all                                Debian Live - System build scripts

  root at 53e16c910d1d:/# lsb_release -a
  No LSB modules are available.
  Distributor ID:	Ubuntu
  Description:	Ubuntu 15.10
  Release:	15.10
  Codename:	wily


  Console output of patched code (both variants):

  root at 53e16c910d1d:/tmp# lb config --iso-volume '123456789-123456789-123456789-123'
  [2016-03-16 15:20:26] lb_config --iso-volume 123456789-123456789-123456789-123
  P: Considering defaults defined in /etc/live/build.conf
  W: You have specified a value of LB_ISO_VOLUME that is too long; the maximum length is 32 characters.
  P: Updating config tree for a ubuntu/amd64 system
  W: You have specified a value of LB_ISO_VOLUME that is too long; the maximum length is 32 characters.

  root at 53e16c910d1d:/tmp# lb config --iso-volume '123456789-123456789-123456789-12'
  [2016-03-16 15:20:29] lb_config --iso-volume 123456789-123456789-123456789-12
  P: Considering defaults defined in /etc/live/build.conf
  P: Updating config tree for a ubuntu/amd64 system

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/live-build/+bug/1558109/+subscriptions



More information about the foundations-bugs mailing list