[SRU] Honour attributes for local assignments in subshells

Bug #2110614 reported by Ponnuvel Palaniyappan
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu
Fix Released
Undecided
Unassigned
Jammy
In Progress
Undecided
Ponnuvel Palaniyappan
Noble
Fix Released
Undecided
Unassigned
ksh93u+m (Ubuntu)
Fix Released
Undecided
Unassigned
Jammy
Fix Released
Medium
Ponnuvel Palaniyappan
Noble
Fix Released
Undecided
Unassigned

Bug Description

[ Impact ]

 Any attributes set for local variables aren't exported to subshells correctly, resulting in incorrect behaviour in the subshells.

This is due to a bug in that, the attributes from the parent aren't copied to the subshells and thus not inherited.

[ Test Plan ]

A reproducer:

```bash
#!/bin/ksh

function called_function_ext {
    echo "In function_ext: int_typeset_declared_in_func_exported: ${int_typeset_declared_in_func_exported}"
}

function call_from_main {
    typeset -i int_typeset_declared_in_func_exported=444

    export int_typeset_declared_in_func_exported
    echo "In call_from_main: int_typeset_declared_in_func_exported: ${int_typeset_declared_in_func_exported}"
    called_function_ext
}

call_from_main
```

It outputs:
```
In call_from_main: int_typeset_declared_in_func_exported: 444
In function_ext: int_typeset_declared_in_func_exported: 3421236
``

Whereas correct output should be:
```
In call_from_main: int_typeset_declared_in_func_exported: 444
In function_ext: int_typeset_declared_in_func_exported: 444
```

[ Where problems could occur ]

Shell's behaviour might be different, or it can't even startup in the worst case.

Potentially attributes might be set incorrectly in the subshells and still exhibit incorrect behaviour.

[ Other Info ]

Upstream bug: https://github.com/ksh93/ksh/issues/465

Upstream fix: https://github.com/ksh93/ksh/commit/870ca92a0821775a400445126bc87ade6b203f94

PPA with this patch: https://launchpad.net/~pponnuvel/+archive/ubuntu/test-ksh93-2110614

This works as expected on Noble which has a new version of ksh that contains this fix.

Changed in ubuntu:
status: New → Fix Released
description: updated
tags: added: sts
summary: - Honour attributes for local assignments in subshells
+ [SRU} Honour attributes for local assignments in subshells
summary: - [SRU} Honour attributes for local assignments in subshells
+ [SRU] Honour attributes for local assignments in subshells
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Attaching debdiff for Jammy.

description: updated
description: updated
description: updated
description: updated
description: updated
Changed in ksh93u+m (Ubuntu Noble):
status: New → Fix Released
Changed in ksh93u+m (Ubuntu):
status: New → Fix Released
Changed in ksh93u+m (Ubuntu Jammy):
status: New → Triaged
importance: Undecided → Medium
assignee: nobody → Ponnuvel Palaniyappan (pponnuvel)
Revision history for this message
Heitor Alves de Siqueira (halves) wrote :

Thanks for the patches, @pponnuvel! A few comments below, before this is ready for upload.

In the debian/changelog entry, please explicitly call out the files you've modified under the `debian/` folder. For this change, this should be the new patch file you've added under `debian/patches/bug2110614.patch`.

On the DEP-3 headers:
- the "Author:" tag should not mention you as this is not your original patch. Given the upstream repo has a COPYRIGHT file and this is a contribution from the upstream ksh maintainer, it should be "Martijn Dekker <email address hidden>"
- the "Origin:" tag is missing the upstream URL

On the actual patch contents, there are some unnecessary changes in the upstream commit. I don't think we need the changes to the NEWS file, so that hunk can be safely dropped. And although including tests for a change is always nice, it doesn't seem that in this specific instance attributes.sh and functions.sh will be run in the Ubuntu packages at all: debian/tests/control and debian/tests/run.sh only execute the "basic.sh" test, and debian/control does not invoke the package's test suite either. We should probably drop those two files from the debdiff, as well.

Once those points are addressed, we can proceed with sponsoring!

Changed in ksh93u+m (Ubuntu Jammy):
status: Triaged → Incomplete
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

@Heitor,

Thanks for the comments. I've addressed them and re-uploaded a new debdiff here. Please take a look. Thanks!

Changed in ksh93u+m (Ubuntu Jammy):
status: Incomplete → In Progress
Revision history for this message
Heitor Alves de Siqueira (halves) wrote :

Thank you, Pon! Some changes I made to your latest debdiff:

- minor changelog adjustments (ubuntu0.1 vs ubuntu1, formatting)
- `Origin: backport` in bug2110614.patch
- added `Backport-Notes:` to bug2110614.patch, explaining the dropped hunks from upstream
- ran `update-maintainer` as this is the first ubuntu revision

Sponsored for Jammy with the changes from above.

Revision history for this message
Nick Rosbrook (enr0n) wrote : Please test proposed package

Hello Ponnuvel, or anyone else affected,

Accepted ksh93u+m into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ksh93u+m/1.0.0~beta.2-1ubuntu0.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in ksh93u+m (Ubuntu Jammy):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-jammy
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

I am unable to do SRU verification as the package isn't uploaded yet.

Looks like it was built successfully, but upload failed: https://launchpad.net/ubuntu/+source/ksh93u+m/1.0.0~beta.2-1ubuntu0.1/+build/30976553

Revision history for this message
Nick Rosbrook (enr0n) wrote :

This is a bug in the source package. It contains the following in debian/rules:

override_dh_gencontrol:
        dh_gencontrol --package=ksh93u+m
        dh_gencontrol --package=ksh -- -v20211217

So, it is always setting the `ksh` package version to 20211217, ignoring the Ubuntu package version.

This is explained in the upload log[1][2]:

DEBUG Considering changefile 1/ubuntu/ksh93u+m_1.0.0~beta.2-1ubuntu0.1_amd64.changes
DEBUG Finding fresh policy
INFO Processing upload ksh93u+m_1.0.0~beta.2-1ubuntu0.1_amd64.changes
INFO Rejection during accept. Aborting partial accept.
INFO Upload was rejected:
INFO The following files are already published in Primary Archive for Ubuntu:
ksh_20211217_all.deb
INFO Committing the transaction and any mails associated with this upload.

[1] https://launchpad.net/ubuntu/+source/ksh93u+m/1.0.0~beta.2-1ubuntu0.1/+build/30976553
[2] https://launchpadlibrarian.net/804445042/upload_30976553_log.txt

tags: added: verification-failed-jammy
removed: verification-needed-jammy
Revision history for this message
Heitor Alves de Siqueira (halves) wrote :

I've opened bug 2117103 for tracking this, and will upload the fixes soon.

Revision history for this message
Nick Rosbrook (enr0n) wrote : Proposed package upload rejected

An upload of ksh93u+m to jammy-proposed has been rejected from the upload queue for the following reason: "See https://bugs.launchpad.net/ubuntu/+source/ksh93u+m/+bug/2117103/comments/1".

Revision history for this message
Nick Rosbrook (enr0n) wrote : Please test proposed package

Hello Ponnuvel, or anyone else affected,

Accepted ksh93u+m into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ksh93u+m/1.0.0~beta.2-1ubuntu0.2 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

tags: added: verification-needed-jammy
removed: verification-failed-jammy
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Verified on Jammy (pkg: 1.0.0~beta.2-1ubuntu0.2):

Confirmed the version is ksh and the new package from -proposed:
```
root@jammy:/tmp/ksh-tests# dpkg -l | grep ksh
ii ksh93u+m 1.0.0~beta.2-1ubuntu0.2 amd64 AT&T KornShell

root@jammy:/tmp/ksh-tests# which ksh
/usr/bin/ksh
root@jammy:/tmp/ksh-tests# which ksh93
/usr/bin/ksh93
root@jammy:/tmp/ksh-tests# readlink -f /usr/bin/ksh
/usr/bin/ksh93
root@jammy:/tmp/ksh-tests# readlink -f /usr/bin/ksh93
/usr/bin/ksh93
root@jammy:/tmp/ksh-tests#

```

Run the test case:
```
root@jammy:/tmp/ksh-tests# cat testcase.sh
#!/bin/ksh

function called_function_ext {
    echo "In function_ext: int_typeset_declared_in_func_exported: ${int_typeset_declared_in_func_exported}"
}

function call_from_main {
    typeset -i int_typeset_declared_in_func_exported=444

    export int_typeset_declared_in_func_exported
    echo "In call_from_main: int_typeset_declared_in_func_exported: ${int_typeset_declared_in_func_exported}"
    called_function_ext
}

call_from_main

root@jammy:/tmp/ksh-tests# ksh ./testcase.sh
In call_from_main: int_typeset_declared_in_func_exported: 444
In function_ext: int_typeset_declared_in_func_exported: 444
```

Execute it directly (with shebang it should use ksh):
```
root@jammy:/tmp/ksh-tests# chmod +x testcase.sh
root@jammy:/tmp/ksh-tests# ./testcase.sh
In call_from_main: int_typeset_declared_in_func_exported: 444
In function_ext: int_typeset_declared_in_func_exported: 444
```

Execute from within the ksh shell:
```
root@jammy:/tmp/ksh-tests# ksh
# pwd
/tmp/ksh-tests
# ./testcase.sh
In call_from_main: int_typeset_declared_in_func_exported: 444
In function_ext: int_typeset_declared_in_func_exported: 444
# ls -l
total 8
-rwxr-xr-x 1 root root 34 Sep 14 10:25 s1.sh
-rwxr-xr-x 1 root root 440 Sep 14 10:46 testcase.sh
# ksh93 ./testcase.sh
In call_from_main: int_typeset_declared_in_func_exported: 444
In function_ext: int_typeset_declared_in_func_exported: 444
#
```

Everything works as expected.

tags: added: verification-done verification-done-jammy
removed: verification-needed verification-needed-jammy
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ksh93u+m - 1.0.0~beta.2-1ubuntu0.2

---------------
ksh93u+m (1.0.0~beta.2-1ubuntu0.2) jammy; urgency=medium

  * Fix hardcoded version number. (LP: #2117103)

ksh93u+m (1.0.0~beta.2-1ubuntu0.1) jammy; urgency=medium

  * Honour attributes for local assignments preceding certain
    commands (LP: #2110614):
    - debian/patches/bug2110614.patch

 -- Dariusz Gadomski <email address hidden> Thu, 04 Sep 2025 09:26:58 +0200

Changed in ksh93u+m (Ubuntu Jammy):
status: Fix Committed → Fix Released
Revision history for this message
Julian Andres Klode (juliank) wrote : Update Released

The verification of the Stable Release Update for ksh93u+m has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.