{"record":{"id":"5e41cf42eadda8d9","repo":"uutils/coreutils","slug":"smack-error-no-label-set","errorCode":null,"errorMessage":"smack-error-no-label-set","messagePattern":"smack-error-no-label-set","errorType":"exception","errorClass":"SmackError::LabelRetrievalFailure","httpStatus":null,"severity":"warning","filePath":"src/uucore/src/lib/features/smack.rs","lineNumber":89,"sourceCode":"pub fn set_smack_label_for_self(label: &str) -> Result<(), SmackError> {\n    if !is_smack_enabled() {\n        return Err(SmackError::SmackNotEnabled);\n    }\n\n    fs::File::create(\"/proc/self/attr/current\")\n        .and_then(|mut f| f.write_all(label.as_bytes()))\n        .map_err(|e| SmackError::LabelSetFailure(label.to_string(), e))\n}\n\n/// Gets the SMACK label for a filesystem path via xattr.\npub fn get_smack_label_for_path(path: &Path) -> Result<String, SmackError> {\n    if !is_smack_enabled() {\n        return Err(SmackError::SmackNotEnabled);\n    }\n\n    match xattr::get(path, \"security.SMACK64\") {\n        Ok(Some(value)) => Ok(String::from_utf8_lossy(&value).trim().to_string()),\n        Ok(None) => Err(SmackError::LabelRetrievalFailure(io::Error::new(\n            io::ErrorKind::NotFound,\n            translate!(\"smack-error-no-label-set\"),\n        ))),\n        Err(e) => Err(SmackError::LabelRetrievalFailure(e)),\n    }\n}\n\n/// Sets the SMACK label for a filesystem path via xattr.\npub fn set_smack_label_for_path(path: &Path, label: &str) -> Result<(), SmackError> {\n    if !is_smack_enabled() {\n        return Err(SmackError::SmackNotEnabled);\n    }\n\n    xattr::set(path, \"security.SMACK64\", label.as_bytes())\n        .map_err(|e| SmackError::LabelSetFailure(label.to_string(), e))\n}\n\n/// Sets SMACK label for a new path, calling cleanup on failure.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/uutils/coreutils/blob/92995feca29e324a7c559ede91db81c32d9f5d59/src/uucore/src/lib/features/smack.rs#L71-L107","documentation":"get_smack_label_for_path reads the security.SMACK64 extended attribute on Smack-enabled systems. If the attribute exists but is unset (xattr returns Some with... Ok(None) meaning no value), it wraps a NotFound io error carrying 'smack-error-no-label-set' in SmackError::LabelRetrievalFailure.","triggerScenarios":"Calling get_smack_label_for_path on a file that has the SMACK64 xattr slot empty or no label assigned — i.e. the file was never labeled by smack.-label or inherited no label.","commonSituations":"Files created on non-Smack filesystems mounted on a Smack system; freshly extracted archives lacking xattrs; tmpfs volumes without Smack labeling.","solutions":["Set a label with `chsmack -a <label> <path>` before reading","Fall back to a default label in your code when LabelRetrievalFailure(NotFound) is returned","Verify the filesystem supports Smack labeling"],"exampleFix":"// before\nlet label = get_smack_label_for_path(path)?;\n// after\nlet label = get_smack_label_for_path(path).unwrap_or_else(|_| \"_\".to_string());","handlingStrategy":"fallback","validationCode":"// xattr presence check (Linux)\nfn has_smack64(path: &Path) -> bool {\n    std::path::Path::new(\"/sys/fs/smackfs\").exists() &&\n        std::fs::read(path).is_ok() // filesystem reachable; label check via xattr crate\n}","typeGuard":null,"tryCatchPattern":"match get_smack_label_for_path(path) {\n    Err(SmackError::LabelRetrievalFailure(e)) if e.kind() == std::io::ErrorKind::NotFound => default_label(),\n    Ok(label) => label,\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Label new files with `chsmack -a` on Smack-enabled systems","Check is_smack_enabled() before querying labels","Don't assume xattrs survive archive extraction or tmpfs"],"tags":["linux","smack","security","xattr"],"backgroundTag":"file-not-found","analyzedSha":"92995feca29e324a7c559ede91db81c32d9f5d59","analyzedAt":"2026-09-20T12:39:35.476Z","contentChangedAt":"2026-09-20T12:39:35.476Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}